Skip to content

Commit 0d2a6e6

Browse files
committed
Merge branch 'LucasED78-master'
2 parents 4f0bdf0 + 9a2c141 commit 0d2a6e6

2 files changed

Lines changed: 81 additions & 33 deletions

File tree

example/lib/main.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class _MyHomePageState extends State<MyHomePage> {
2626
bool status3 = false;
2727
bool status4 = false;
2828
bool status5 = false;
29+
bool status6 = false;
2930

3031
@override
3132
Widget build(BuildContext context) {
@@ -164,6 +165,34 @@ class _MyHomePageState extends State<MyHomePage> {
164165
),
165166
],
166167
),
168+
SizedBox(height: 20.0),
169+
Text("Custom text"),
170+
SizedBox(height: 10.0),
171+
Row(
172+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
173+
children: <Widget>[
174+
FlutterSwitch(
175+
activeText: "All Good",
176+
offText: "Under Quarantine",
177+
value: status6,
178+
valueFontSize: 10.0,
179+
width: 110,
180+
borderRadius: 30.0,
181+
showOnOff: true,
182+
onToggle: (val) {
183+
setState(() {
184+
status6 = val;
185+
});
186+
},
187+
),
188+
Container(
189+
alignment: Alignment.centerRight,
190+
child: Text(
191+
"Value: $status6",
192+
),
193+
),
194+
],
195+
)
167196
],
168197
),
169198
),

lib/flutter_switch.dart

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)