@@ -16,7 +16,7 @@ class GFToggle extends StatefulWidget {
1616 GFToggle (
1717 {Key key,
1818 @required this .onChanged,
19- this .value ,
19+ this .value,
2020 this .enabledText,
2121 this .disabledText,
2222 this .enabledTextStyle,
@@ -73,7 +73,6 @@ class GFToggle extends StatefulWidget {
7373 /// Called when the user toggles the switch on or off.
7474 final ValueChanged <bool > onChanged;
7575
76-
7776 @override
7877 _GFToggleState createState () => _GFToggleState ();
7978}
@@ -86,15 +85,15 @@ class _GFToggleState extends State<GFToggle> with TickerProviderStateMixin {
8685
8786 bool isOn;
8887
89-
90-
9188 @override
9289 void initState () {
9390 setState (() {
94- isOn = widget.value?? false ;
91+ isOn = widget.value ?? false ;
9592 });
9693 controller = AnimationController (vsync: this , duration: widget.duration);
97- offset = (isOn? Tween <Offset >(begin: Offset (1.0 , 0.0 ), end: Offset .zero): Tween <Offset >(begin: Offset .zero, end: Offset (1.0 , 0.0 )))
94+ offset = (isOn
95+ ? Tween <Offset >(begin: Offset (1.0 , 0.0 ), end: Offset .zero)
96+ : Tween <Offset >(begin: Offset .zero, end: Offset (1.0 , 0.0 )))
9897 .animate (controller);
9998 super .initState ();
10099 }
@@ -106,8 +105,8 @@ class _GFToggleState extends State<GFToggle> with TickerProviderStateMixin {
106105 super .dispose ();
107106 }
108107
109- void onStatusChange (){
110- if (widget.onChanged!= null ){
108+ void onStatusChange () {
109+ if (widget.onChanged != null ) {
111110 setState (() {
112111 isOn = ! isOn;
113112 });
@@ -127,84 +126,79 @@ class _GFToggleState extends State<GFToggle> with TickerProviderStateMixin {
127126
128127 @override
129128 Widget build (BuildContext context) {
130- return Stack (
131- children: < Widget > [
132- Container (
133- height: widget.type == GFToggleType .android ? 25 : 30 ,
134- width: widget.type == GFToggleType .android ? 40 : 50 ,
135- ),
136- Positioned (
137- top: 5 ,
138- child: InkWell (
129+ return Stack (
130+ children: < Widget > [
131+ Container (
132+ height: widget.type == GFToggleType .android ? 25 : 30 ,
133+ width: widget.type == GFToggleType .android ? 40 : 50 ,
134+ ),
135+ Positioned (
136+ top: 5 ,
137+ child: InkWell (
139138 onTap: onStatusChange,
140139 child: Container (
141- width: widget.type == GFToggleType .ios ? 45 : 36 ,
142- height: widget.type == GFToggleType .ios ? 25 : 15 ,
143- decoration: BoxDecoration (
144- color: isOn
145- ? widget.enabledTrackColor ?? Colors .lightGreen
146- : widget.disabledTrackColor ?? Colors .grey,
147- borderRadius: widget.type == GFToggleType .square
148- ? BorderRadius .all (Radius .circular (0 ))
149- : widget.borderRadius ??
140+ width: widget.type == GFToggleType .ios ? 45 : 36 ,
141+ height: widget.type == GFToggleType .ios ? 25 : 15 ,
142+ decoration: BoxDecoration (
143+ color: isOn
144+ ? widget.enabledTrackColor ?? Colors .lightGreen
145+ : widget.disabledTrackColor ?? Colors .grey,
146+ borderRadius: widget.type == GFToggleType .square
147+ ? BorderRadius .all (Radius .circular (0 ))
148+ : widget.borderRadius ??
150149 BorderRadius .all (Radius .circular (20 ))),
151- child: Padding (
152- padding: widget.type == GFToggleType .ios
153- ? EdgeInsets .only (left: 3.5 , right: 3.5 , top: 5.4 )
154- : EdgeInsets .only (left: 3 , right: 3 , top: 3.4 ),
155- child: isOn
156- ? Text (
157- widget.enabledText ??
158- (widget.type == GFToggleType .custom
159- ? 'ON'
160- : '' ),
161- style: widget.enabledTextStyle ??
162- (widget.type == GFToggleType .ios
163- ? TextStyle (
164- color: Colors .white, fontSize: 12 )
165- : TextStyle (
166- color: Colors .white, fontSize: 8 )))
167- : Text (
168- widget.disabledText ??
169- (widget.type == GFToggleType .custom
170- ? 'OFF'
171- : '' ),
172- textAlign: TextAlign .end,
173- style: widget.disabledTextStyle ??
174- (widget.type == GFToggleType .ios
175- ? TextStyle (color: Colors .white, fontSize: 12 )
176- : TextStyle (color: Colors .white, fontSize: 8 )),),),),
177- ),),
178- Positioned (
179- top: widget.type == GFToggleType .ios ? 7.5 : 3 ,
180- left: widget.type == GFToggleType .ios ? 2 : 0 ,
181- child: InkWell (
182- onTap: onStatusChange,
183- child: SlideTransition (
184- position: offset,
185- child: Container (
186- padding: EdgeInsets .only (left: 10 ),
187- height: 20 ,
188- width: 20 ,
189- decoration: BoxDecoration (
190- shape: widget.type == GFToggleType .square
191- ? BoxShape .rectangle
192- : widget.boxShape ?? BoxShape .circle,
193- color: isOn
194- ? widget.enabledThumbColor ?? Colors .white
195- : widget.disabledThumbColor ?? Colors .white,
196- boxShadow: [
197- new BoxShadow (
198- color: Colors .black.withOpacity (0.16 ),
199- blurRadius: 6.0 ,
200- spreadRadius: 0.0 ),
201- ]),
150+ child: Padding (
151+ padding: widget.type == GFToggleType .ios
152+ ? EdgeInsets .only (left: 3.5 , right: 3.5 , top: 5.4 )
153+ : EdgeInsets .only (left: 3 , right: 3 , top: 3.4 ),
154+ child: isOn
155+ ? Text (
156+ widget.enabledText ??
157+ (widget.type == GFToggleType .custom ? 'ON' : '' ),
158+ style: widget.enabledTextStyle ??
159+ (widget.type == GFToggleType .ios
160+ ? TextStyle (color: Colors .white, fontSize: 12 )
161+ : TextStyle (color: Colors .white, fontSize: 8 )))
162+ : Text (
163+ widget.disabledText ??
164+ (widget.type == GFToggleType .custom ? 'OFF' : '' ),
165+ textAlign: TextAlign .end,
166+ style: widget.disabledTextStyle ??
167+ (widget.type == GFToggleType .ios
168+ ? TextStyle (color: Colors .white, fontSize: 12 )
169+ : TextStyle (color: Colors .white, fontSize: 8 )),
202170 ),
203- )
204- )),
205- ],
206-
207- );
171+ ),
172+ ),
173+ ),
174+ ),
175+ Positioned (
176+ top: widget.type == GFToggleType .ios ? 7.5 : 3 ,
177+ left: widget.type == GFToggleType .ios ? 2 : 0 ,
178+ child: InkWell (
179+ onTap: onStatusChange,
180+ child: SlideTransition (
181+ position: offset,
182+ child: Container (
183+ padding: EdgeInsets .only (left: 10 ),
184+ height: 20 ,
185+ width: 20 ,
186+ decoration: BoxDecoration (
187+ shape: widget.type == GFToggleType .square
188+ ? BoxShape .rectangle
189+ : widget.boxShape ?? BoxShape .circle,
190+ color: isOn
191+ ? widget.enabledThumbColor ?? Colors .white
192+ : widget.disabledThumbColor ?? Colors .white,
193+ boxShadow: [
194+ new BoxShadow (
195+ color: Colors .black.withOpacity (0.16 ),
196+ blurRadius: 6.0 ,
197+ spreadRadius: 0.0 ),
198+ ]),
199+ ),
200+ ))),
201+ ],
202+ );
208203 }
209204}
210-
0 commit comments