@@ -11,24 +11,27 @@ class FlutterSwitch extends StatefulWidget {
1111 inactiveTextColor,
1212 toggleColor;
1313 final double width, height, toggleSize, valueFontSize, borderRadius, padding;
14+ final String activeText, offText;
1415
15- const FlutterSwitch ({
16- Key key,
17- this .value,
18- this .onToggle,
19- this .activeColor = Colors .blue,
20- this .inactiveColor = Colors .grey,
21- this .activeTextColor = Colors .white70,
22- this .inactiveTextColor = Colors .white70,
23- this .toggleColor = Colors .white,
24- this .width = 70.0 ,
25- this .height = 35.0 ,
26- this .toggleSize = 25.0 ,
27- this .valueFontSize = 16.0 ,
28- this .borderRadius = 20.0 ,
29- this .padding = 4.0 ,
30- this .showOnOff = false ,
31- }) : super (key: key);
16+ const FlutterSwitch (
17+ {Key key,
18+ this .value,
19+ this .onToggle,
20+ this .activeColor = Colors .blue,
21+ this .inactiveColor = Colors .grey,
22+ this .activeTextColor = Colors .white70,
23+ this .inactiveTextColor = Colors .white70,
24+ this .toggleColor = Colors .white,
25+ this .width = 70.0 ,
26+ this .height = 35.0 ,
27+ this .toggleSize = 25.0 ,
28+ this .valueFontSize = 16.0 ,
29+ this .borderRadius = 20.0 ,
30+ this .padding = 4.0 ,
31+ this .showOnOff = false ,
32+ this .activeText,
33+ this .offText})
34+ : super (key: key);
3235
3336 @override
3437 _FlutterSwitchState createState () => _FlutterSwitchState ();
@@ -87,14 +90,7 @@ class _FlutterSwitchState extends State<FlutterSwitch>
8790 ? Expanded (
8891 child: Container (
8992 padding: EdgeInsets .symmetric (horizontal: 4.0 ),
90- child: Text (
91- widget.showOnOff ? "On" : "" ,
92- style: TextStyle (
93- color: widget.activeTextColor,
94- fontWeight: FontWeight .w900,
95- fontSize: widget.valueFontSize,
96- ),
97- ),
93+ child: _activeText,
9894 ),
9995 )
10096 : Container (),
@@ -114,14 +110,7 @@ class _FlutterSwitchState extends State<FlutterSwitch>
114110 child: Container (
115111 padding: EdgeInsets .symmetric (horizontal: 4.0 ),
116112 alignment: Alignment .centerRight,
117- child: Text (
118- widget.showOnOff ? "Off" : "" ,
119- style: TextStyle (
120- color: widget.inactiveTextColor,
121- fontWeight: FontWeight .w900,
122- fontSize: widget.valueFontSize,
123- ),
124- ),
113+ child: _offText,
125114 ),
126115 )
127116 : Container (),
@@ -132,4 +121,34 @@ class _FlutterSwitchState extends State<FlutterSwitch>
132121 },
133122 );
134123 }
124+
125+ Widget get _activeText {
126+ if (widget.showOnOff) {
127+ return Text (
128+ (widget? .activeText != null ) ? widget.activeText : "On" ,
129+ style: TextStyle (
130+ color: widget.activeTextColor,
131+ fontWeight: FontWeight .w900,
132+ fontSize: widget.valueFontSize,
133+ ),
134+ );
135+ }
136+
137+ return Text ("" );
138+ }
139+
140+ Widget get _offText {
141+ if (widget.showOnOff) {
142+ return Text (
143+ (widget? .offText != null ) ? widget.offText : "Off" ,
144+ style: TextStyle (
145+ color: widget.inactiveTextColor,
146+ fontWeight: FontWeight .w900,
147+ fontSize: widget.valueFontSize,
148+ ),
149+ );
150+ }
151+
152+ return Text ("" );
153+ }
135154}
0 commit comments