-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswitch_button.dart
52 lines (46 loc) · 1.4 KB
/
switch_button.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
library switch_button;
import 'package:flutter/material.dart';
class SwitchButton extends StatefulWidget {
final bool switchValue;
final ValueChanged<bool> onChanged;
final double size;
final Color activeColor;
final Color activeTrackColor;
final Color inactiveThumbColor;
final Color inactiveTrackColor;
const SwitchButton({
required Key key,
required this.switchValue,
required this.onChanged,
this.size = 2.0,
this.activeColor = Colors.black12,
this.activeTrackColor = Colors.pink,
this.inactiveThumbColor = Colors.white,
this.inactiveTrackColor = Colors.grey,
}) : super(key: key);
@override
SwitchButtonState createState() => SwitchButtonState();
}
class SwitchButtonState extends State<SwitchButton>
with SingleTickerProviderStateMixin {
void toggleSwitch(bool value) {
setState(() {
widget.onChanged(value);
});
}
@override
Widget build(BuildContext context) {
return Column(mainAxisAlignment: MainAxisAlignment.center, children: [
Transform.scale(
scale: widget.size,
child: Switch(
onChanged: toggleSwitch,
value: widget.switchValue,
activeColor: widget.activeColor,
activeTrackColor: widget.activeTrackColor,
inactiveThumbColor: widget.inactiveThumbColor,
inactiveTrackColor: widget.inactiveTrackColor,
)),
]);
}
}