@@ -12,14 +12,14 @@ class FlutterSwitch extends StatefulWidget {
1212 ///
1313
1414 const FlutterSwitch ({
15- Key key,
16- @ required this .value,
17- @ required this .onToggle,
15+ Key ? key,
16+ required this .value,
17+ required this .onToggle,
1818 this .activeColor = Colors .blue,
1919 this .inactiveColor = Colors .grey,
2020 this .activeTextColor = Colors .white70,
2121 this .inactiveTextColor = Colors .white70,
22- this .toggleColor,
22+ this .toggleColor = Colors .white ,
2323 this .activeToggleColor,
2424 this .inactiveToggleColor,
2525 this .width = 70.0 ,
@@ -43,11 +43,6 @@ class FlutterSwitch extends StatefulWidget {
4343 this .inactiveIcon,
4444 this .duration = const Duration (milliseconds: 200 ),
4545 }) : assert (
46- (toggleColor == null || activeToggleColor == null ) &&
47- (toggleColor == null || inactiveToggleColor == null ),
48- 'Cannot provide toggleColor when an activeToggleColor or inactiveToggleColor was given\n '
49- 'To give the toggle a color, use "activeToggleColor: color" and "inactiveToggleColor: color".' ),
50- assert (
5146 (switchBorder == null || activeSwitchBorder == null ) &&
5247 (switchBorder == null || inactiveSwitchBorder == null ),
5348 'Cannot provide switchBorder when an activeSwitchBorder or inactiveSwitchBorder was given\n '
@@ -102,7 +97,7 @@ class FlutterSwitch extends StatefulWidget {
10297 ///
10398 /// [activeTextColor] - The color to use on the text value when the switch is on.
10499 /// [activeTextFontWeight] - The font weight to use on the text value when the switch is on.
105- final String activeText;
100+ final String ? activeText;
106101
107102 /// The text to display when the switch is off.
108103 /// This parameter is only necessary when [showOnOff] property is true.
@@ -113,7 +108,7 @@ class FlutterSwitch extends StatefulWidget {
113108 ///
114109 /// [inactiveTextColor] - The color to use on the text value when the switch is off.
115110 /// [inactiveTextFontWeight] - The font weight to use on the text value when the switch is off.
116- final String inactiveText;
111+ final String ? inactiveText;
117112
118113 /// The color to use on the switch when the switch is on.
119114 ///
@@ -141,13 +136,13 @@ class FlutterSwitch extends StatefulWidget {
141136 /// This parameter is only necessary when [showOnOff] property is true.
142137 ///
143138 /// Defaults to [FontWeight.w900] .
144- final FontWeight activeTextFontWeight;
139+ final FontWeight ? activeTextFontWeight;
145140
146141 /// The font weight to use on the text value when the switch is off.
147142 /// This parameter is only necessary when [showOnOff] property is true.
148143 ///
149144 /// Defaults to [FontWeight.w900] .
150- final FontWeight inactiveTextFontWeight;
145+ final FontWeight ? inactiveTextFontWeight;
151146
152147 /// The color to use on the toggle of the switch.
153148 ///
@@ -160,13 +155,13 @@ class FlutterSwitch extends StatefulWidget {
160155 ///
161156 /// If [inactiveToggleColor] is used and this property is null. the value of
162157 /// [Colors.white] will be used.
163- final Color activeToggleColor;
158+ final Color ? activeToggleColor;
164159
165160 /// The color to use on the toggle of the switch when the given value is false.
166161 ///
167162 /// If [activeToggleColor] is used and this property is null. the value of
168163 /// [Colors.white] will be used.
169- final Color inactiveToggleColor;
164+ final Color ? inactiveToggleColor;
170165
171166 /// The given width of the switch.
172167 ///
@@ -204,44 +199,44 @@ class FlutterSwitch extends StatefulWidget {
204199 /// This property will give a uniform border to both states of the toggle
205200 ///
206201 /// If the [activeSwitchBorder] or [inactiveSwitchBorder] is used, this property must be null.
207- final BoxBorder switchBorder;
202+ final BoxBorder ? switchBorder;
208203
209204 /// The border of the switch when the given value is true.
210205 ///
211206 /// This property is optional.
212- final BoxBorder activeSwitchBorder;
207+ final BoxBorder ? activeSwitchBorder;
213208
214209 /// The border of the switch when the given value is false.
215210 ///
216211 /// This property is optional.
217- final BoxBorder inactiveSwitchBorder;
212+ final BoxBorder ? inactiveSwitchBorder;
218213
219214 /// The border of the toggle.
220215 ///
221216 /// This property will give a uniform border to both states of the toggle
222217 ///
223218 /// If the [activeToggleBorder] or [inactiveToggleBorder] is used, this property must be null.
224- final BoxBorder toggleBorder;
219+ final BoxBorder ? toggleBorder;
225220
226221 /// The border of the toggle when the given value is true.
227222 ///
228223 /// This property is optional.
229- final BoxBorder activeToggleBorder;
224+ final BoxBorder ? activeToggleBorder;
230225
231226 /// The border of the toggle when the given value is false.
232227 ///
233228 /// This property is optional.
234- final BoxBorder inactiveToggleBorder;
229+ final BoxBorder ? inactiveToggleBorder;
235230
236231 /// The icon inside the toggle when the given value is true.
237232 ///
238233 /// This property is optional.
239- final Icon activeIcon;
234+ final Icon ? activeIcon;
240235
241236 /// The icon inside the toggle when the given value is false.
242237 ///
243238 /// This property is optional.
244- final Icon inactiveIcon;
239+ final Icon ? inactiveIcon;
245240
246241 /// The duration in milliseconds to change the state of the switch
247242 ///
@@ -254,8 +249,8 @@ class FlutterSwitch extends StatefulWidget {
254249
255250class _FlutterSwitchState extends State <FlutterSwitch >
256251 with SingleTickerProviderStateMixin {
257- Animation _toggleAnimation;
258- AnimationController _animationController;
252+ late final Animation _toggleAnimation;
253+ late final AnimationController _animationController;
259254
260255 @override
261256 void initState () {
@@ -298,19 +293,23 @@ class _FlutterSwitchState extends State<FlutterSwitch>
298293 Widget build (BuildContext context) {
299294 Color _toggleColor = Colors .white;
300295 Color _switchColor = Colors .white;
301- Border _switchBorder;
302- Border _toggleBorder;
296+ Border ? _switchBorder;
297+ Border ? _toggleBorder;
303298
304299 if (widget.value) {
305300 _toggleColor = widget.activeToggleColor ?? widget.toggleColor;
306301 _switchColor = widget.activeColor;
307- _switchBorder = widget.activeSwitchBorder ?? widget.switchBorder;
308- _toggleBorder = widget.activeToggleBorder ?? widget.toggleBorder;
302+ _switchBorder = widget.activeSwitchBorder as Border ? ??
303+ widget.switchBorder as Border ? ;
304+ _toggleBorder = widget.activeToggleBorder as Border ? ??
305+ widget.toggleBorder as Border ? ;
309306 } else {
310307 _toggleColor = widget.inactiveToggleColor ?? widget.toggleColor;
311308 _switchColor = widget.inactiveColor;
312- _switchBorder = widget.inactiveSwitchBorder ?? widget.switchBorder;
313- _toggleBorder = widget.inactiveToggleBorder ?? widget.toggleBorder;
309+ _switchBorder = widget.inactiveSwitchBorder as Border ? ??
310+ widget.switchBorder as Border ? ;
311+ _toggleBorder = widget.inactiveToggleBorder as Border ? ??
312+ widget.toggleBorder as Border ? ;
314313 }
315314
316315 double _textSpace = widget.width - widget.toggleSize;
@@ -370,7 +369,7 @@ class _FlutterSwitchState extends State<FlutterSwitch>
370369 height: widget.toggleSize,
371370 decoration: BoxDecoration (
372371 shape: BoxShape .circle,
373- color: _toggleColor ?? Colors .white ,
372+ color: _toggleColor,
374373 border: _toggleBorder,
375374 ),
376375 child: Container (
@@ -405,18 +404,15 @@ class _FlutterSwitchState extends State<FlutterSwitch>
405404 );
406405 }
407406
408- FontWeight get _activeTextFontWeight => widget.activeTextFontWeight != null
409- ? widget.activeTextFontWeight
410- : FontWeight .w900;
407+ FontWeight get _activeTextFontWeight =>
408+ widget.activeTextFontWeight ?? FontWeight .w900;
411409 FontWeight get _inactiveTextFontWeight =>
412- widget.inactiveTextFontWeight != null
413- ? widget.inactiveTextFontWeight
414- : FontWeight .w900;
410+ widget.inactiveTextFontWeight ?? FontWeight .w900;
415411
416412 Widget get _activeText {
417413 if (widget.showOnOff) {
418414 return Text (
419- ( widget? .activeText != null ) ? widget.activeText : "On" ,
415+ widget.activeText ?? "On" ,
420416 style: TextStyle (
421417 color: widget.activeTextColor,
422418 fontWeight: _activeTextFontWeight,
@@ -431,7 +427,7 @@ class _FlutterSwitchState extends State<FlutterSwitch>
431427 Widget get _inactiveText {
432428 if (widget.showOnOff) {
433429 return Text (
434- ( widget? .inactiveText != null ) ? widget.inactiveText : "Off" ,
430+ widget.inactiveText ?? "Off" ,
435431 style: TextStyle (
436432 color: widget.inactiveTextColor,
437433 fontWeight: _inactiveTextFontWeight,
0 commit comments