Skip to content

Commit 13aeafd

Browse files
committed
added switch and toggel border properties
1 parent 18b733c commit 13aeafd

2 files changed

Lines changed: 64 additions & 1 deletion

File tree

example/lib/main.dart

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class _MyHomePageState extends State<MyHomePage> {
2727
bool status4 = false;
2828
bool status5 = false;
2929
bool status6 = false;
30+
bool status7 = true;
3031

3132
@override
3233
Widget build(BuildContext context) {
@@ -192,7 +193,45 @@ class _MyHomePageState extends State<MyHomePage> {
192193
),
193194
),
194195
],
195-
)
196+
),
197+
SizedBox(height: 20.0),
198+
Text("Toon-like feel by using Borders"),
199+
SizedBox(height: 10.0),
200+
Row(
201+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
202+
children: <Widget>[
203+
FlutterSwitch(
204+
width: 125.0,
205+
height: 55.0,
206+
valueFontSize: 25.0,
207+
toggleSize: 45.0,
208+
value: status7,
209+
borderRadius: 30.0,
210+
padding: 2.0,
211+
switchBorder: Border.all(
212+
color: Color.fromRGBO(2, 107, 206, 1),
213+
width: 6.0,
214+
),
215+
toggleBorder: Border.all(
216+
color: Color.fromRGBO(2, 107, 206, 1),
217+
width: 5.0,
218+
),
219+
activeColor: Color.fromRGBO(51, 226, 255, 1),
220+
inactiveColor: Colors.black38,
221+
onToggle: (val) {
222+
setState(() {
223+
status7 = val;
224+
});
225+
},
226+
),
227+
Container(
228+
alignment: Alignment.centerRight,
229+
child: Text(
230+
"Value: $status7",
231+
),
232+
),
233+
],
234+
),
196235
],
197236
),
198237
),

lib/flutter_switch.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class FlutterSwitch extends StatefulWidget {
3131
this.inactiveText,
3232
this.activeTextFontWeight,
3333
this.inactiveTextFontWeight,
34+
this.switchBorder,
35+
this.toggleBorder,
3436
}) : super(key: key);
3537

3638
/// Determines if the switch is on or off.
@@ -159,6 +161,26 @@ class FlutterSwitch extends StatefulWidget {
159161
/// Defaults to the value of 4.0.
160162
final double padding;
161163

164+
/// Determines the border of the switch.
165+
///
166+
/// An example usage would be...
167+
/// ```dart
168+
/// switchBorder: Border.all(color: Color.fromRGBO(2, 107, 206, 1), width: 6.0,)
169+
/// ```
170+
///
171+
/// This is an optional property
172+
final BoxBorder switchBorder;
173+
174+
/// Determines the border of the toggle.
175+
///
176+
/// An example usage would be...
177+
/// ```dart
178+
/// toggleBorder: Border.all(color: Color.fromRGBO(2, 107, 206, 1), width: 4.0,)
179+
/// ```
180+
///
181+
/// This is an optional property
182+
final BoxBorder toggleBorder;
183+
162184
@override
163185
_FlutterSwitchState createState() => _FlutterSwitchState();
164186
}
@@ -225,6 +247,7 @@ class _FlutterSwitchState extends State<FlutterSwitch>
225247
color: _toggleAnimation.value == Alignment.centerLeft
226248
? widget.inactiveColor
227249
: widget.activeColor,
250+
border: widget.switchBorder ?? null,
228251
),
229252
child: Row(
230253
mainAxisAlignment: MainAxisAlignment.spaceBetween,
@@ -245,6 +268,7 @@ class _FlutterSwitchState extends State<FlutterSwitch>
245268
decoration: BoxDecoration(
246269
shape: BoxShape.circle,
247270
color: widget.toggleColor,
271+
border: widget.toggleBorder ?? null,
248272
),
249273
),
250274
),

0 commit comments

Comments
 (0)