Skip to content

Commit 9a2c141

Browse files
committed
Some minor changes with the custom text
1 parent aa04df5 commit 9a2c141

2 files changed

Lines changed: 26 additions & 40 deletions

File tree

example/lib/main.dart

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -172,19 +172,10 @@ class _MyHomePageState extends State<MyHomePage> {
172172
mainAxisAlignment: MainAxisAlignment.spaceBetween,
173173
children: <Widget>[
174174
FlutterSwitch(
175-
activeText: Text(
176-
"custom",
177-
style: TextStyle(
178-
color: Colors.white
179-
),
180-
),
181-
offText: Text(
182-
"Custom2",
183-
style: TextStyle(
184-
color: Colors.black87
185-
),
186-
),
175+
activeText: "All Good",
176+
offText: "Under Quarantine",
187177
value: status6,
178+
valueFontSize: 10.0,
188179
width: 110,
189180
borderRadius: 30.0,
190181
showOnOff: true,

lib/flutter_switch.dart

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,27 @@ 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;
14+
final String activeText, offText;
1615

17-
const FlutterSwitch({
18-
Key key,
19-
this.value,
20-
this.onToggle,
21-
this.activeColor = Colors.blue,
22-
this.inactiveColor = Colors.grey,
23-
this.activeTextColor = Colors.white70,
24-
this.inactiveTextColor = Colors.white70,
25-
this.toggleColor = Colors.white,
26-
this.width = 70.0,
27-
this.height = 35.0,
28-
this.toggleSize = 25.0,
29-
this.valueFontSize = 16.0,
30-
this.borderRadius = 20.0,
31-
this.padding = 4.0,
32-
this.showOnOff = false,
33-
this.activeText,
34-
this.offText
35-
}) : 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);
3635

3736
@override
3837
_FlutterSwitchState createState() => _FlutterSwitchState();
@@ -125,11 +124,9 @@ class _FlutterSwitchState extends State<FlutterSwitch>
125124

126125
Widget get _activeText {
127126
if (widget.showOnOff) {
128-
if (widget?.activeText != null) return widget.activeText;
129-
130127
return Text(
131-
"On",
132-
style: TextStyle(
128+
(widget?.activeText != null) ? widget.activeText : "On",
129+
style: TextStyle(
133130
color: widget.activeTextColor,
134131
fontWeight: FontWeight.w900,
135132
fontSize: widget.valueFontSize,
@@ -142,10 +139,8 @@ class _FlutterSwitchState extends State<FlutterSwitch>
142139

143140
Widget get _offText {
144141
if (widget.showOnOff) {
145-
if (widget?.offText != null) return widget.offText;
146-
147142
return Text(
148-
"Off",
143+
(widget?.offText != null) ? widget.offText : "Off",
149144
style: TextStyle(
150145
color: widget.inactiveTextColor,
151146
fontWeight: FontWeight.w900,

0 commit comments

Comments
 (0)