Skip to content

Commit 1dea3f0

Browse files
committed
added ability to change toggle color
1 parent b36eab5 commit 1dea3f0

5 files changed

Lines changed: 19 additions & 17 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
## [0.0.1] - TODO: Add release date.
1+
## [0.1.0] - May 10, 2020
22

33
* TODO: Describe initial release.

example/lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class _MyHomePageState extends State<MyHomePage> {
6868
FlutterSwitch(
6969
activeColor: Colors.red,
7070
inactiveColor: Colors.red[200],
71+
toggleColor: Colors.blueGrey[700],
7172
value: status2,
7273
onToggle: (val) {
7374
setState(() {

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ packages:
7575
path: ".."
7676
relative: true
7777
source: path
78-
version: "0.0.3"
78+
version: "0.1.0"
7979
flutter_test:
8080
dependency: "direct dev"
8181
description: flutter

lib/flutter_switch.dart

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ library flutter_switch;
33
import 'package:flutter/material.dart';
44

55
class FlutterSwitch extends StatefulWidget {
6-
final bool value;
6+
final bool value, showOnOff;
77
final ValueChanged<bool> onToggle;
8-
final Color activeColor;
9-
final Color inactiveColor;
10-
final Color activeTextColor;
11-
final Color inactiveTextColor;
8+
final Color activeColor,
9+
inactiveColor,
10+
activeTextColor,
11+
inactiveTextColor,
12+
toggleColor;
1213
final double width, height, toggleSize, valueFontSize, borderRadius, padding;
13-
final bool showOnOff;
1414

1515
const FlutterSwitch({
1616
Key key,
@@ -20,6 +20,7 @@ class FlutterSwitch extends StatefulWidget {
2020
this.inactiveColor = Colors.grey,
2121
this.activeTextColor = Colors.white70,
2222
this.inactiveTextColor = Colors.white70,
23+
this.toggleColor = Colors.white,
2324
this.width = 70.0,
2425
this.height = 35.0,
2526
this.toggleSize = 25.0,
@@ -35,7 +36,7 @@ class FlutterSwitch extends StatefulWidget {
3536

3637
class _FlutterSwitchState extends State<FlutterSwitch>
3738
with SingleTickerProviderStateMixin {
38-
Animation _circleAnimation;
39+
Animation _toggleAnimation;
3940
AnimationController _animationController;
4041

4142
@override
@@ -45,7 +46,7 @@ class _FlutterSwitchState extends State<FlutterSwitch>
4546
vsync: this,
4647
duration: Duration(milliseconds: 60),
4748
);
48-
_circleAnimation = AlignmentTween(
49+
_toggleAnimation = AlignmentTween(
4950
begin: widget.value ? Alignment.centerRight : Alignment.centerLeft,
5051
end: widget.value ? Alignment.centerLeft : Alignment.centerRight,
5152
).animate(
@@ -75,14 +76,14 @@ class _FlutterSwitchState extends State<FlutterSwitch>
7576
padding: EdgeInsets.all(widget.padding),
7677
decoration: BoxDecoration(
7778
borderRadius: BorderRadius.circular(widget.borderRadius),
78-
color: _circleAnimation.value == Alignment.centerLeft
79+
color: _toggleAnimation.value == Alignment.centerLeft
7980
? widget.inactiveColor
8081
: widget.activeColor,
8182
),
8283
child: Row(
8384
mainAxisAlignment: MainAxisAlignment.spaceBetween,
8485
children: <Widget>[
85-
_circleAnimation.value == Alignment.centerRight
86+
_toggleAnimation.value == Alignment.centerRight
8687
? Expanded(
8788
child: Container(
8889
padding: EdgeInsets.symmetric(horizontal: 4.0),
@@ -98,17 +99,17 @@ class _FlutterSwitchState extends State<FlutterSwitch>
9899
)
99100
: Container(),
100101
Align(
101-
alignment: _circleAnimation.value,
102+
alignment: _toggleAnimation.value,
102103
child: Container(
103104
width: widget.toggleSize,
104105
height: widget.toggleSize,
105106
decoration: BoxDecoration(
106107
shape: BoxShape.circle,
107-
color: Colors.white,
108+
color: widget.toggleColor,
108109
),
109110
),
110111
),
111-
_circleAnimation.value == Alignment.centerLeft
112+
_toggleAnimation.value == Alignment.centerLeft
112113
? Expanded(
113114
child: Container(
114115
padding: EdgeInsets.symmetric(horizontal: 4.0),

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_switch
2-
description: A Custom Switch package created for Flutter.
3-
version: 0.0.3
2+
description: An easy to implement custom switch that can have a customized the height and width, border radius, colors, toggle size and choice to display an 'On' and 'Off' text.
3+
version: 0.1.0
44
homepage: https://github.com/boringdeveloper/FlutterSwitch
55

66
environment:

0 commit comments

Comments
 (0)