@@ -11,6 +11,8 @@ class FlutterSwitch extends StatefulWidget {
1111 inactiveTextColor,
1212 toggleColor;
1313 final double width, height, toggleSize, valueFontSize, borderRadius, padding;
14+ final Widget activeText;
15+ final Widget offText;
1416
1517 const FlutterSwitch ({
1618 Key key,
@@ -28,6 +30,8 @@ class FlutterSwitch extends StatefulWidget {
2830 this .borderRadius = 20.0 ,
2931 this .padding = 4.0 ,
3032 this .showOnOff = false ,
33+ this .activeText,
34+ this .offText
3135 }) : super (key: key);
3236
3337 @override
@@ -87,14 +91,7 @@ class _FlutterSwitchState extends State<FlutterSwitch>
8791 ? Expanded (
8892 child: Container (
8993 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- ),
94+ child: _activeText,
9895 ),
9996 )
10097 : Container (),
@@ -114,14 +111,7 @@ class _FlutterSwitchState extends State<FlutterSwitch>
114111 child: Container (
115112 padding: EdgeInsets .symmetric (horizontal: 4.0 ),
116113 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- ),
114+ child: _offText,
125115 ),
126116 )
127117 : Container (),
@@ -132,4 +122,38 @@ class _FlutterSwitchState extends State<FlutterSwitch>
132122 },
133123 );
134124 }
125+
126+ Widget get _activeText {
127+ if (widget.showOnOff) {
128+ if (widget? .activeText != null ) return widget.activeText;
129+
130+ return Text (
131+ "On" ,
132+ style: TextStyle (
133+ color: widget.activeTextColor,
134+ fontWeight: FontWeight .w900,
135+ fontSize: widget.valueFontSize,
136+ ),
137+ );
138+ }
139+
140+ return Text ("" );
141+ }
142+
143+ Widget get _offText {
144+ if (widget.showOnOff) {
145+ if (widget? .offText != null ) return widget.offText;
146+
147+ return Text (
148+ "Off" ,
149+ style: TextStyle (
150+ color: widget.inactiveTextColor,
151+ fontWeight: FontWeight .w900,
152+ fontSize: widget.valueFontSize,
153+ ),
154+ );
155+ }
156+
157+ return Text ("" );
158+ }
135159}
0 commit comments