-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswitch_cover_button.dart
51 lines (45 loc) · 1.34 KB
/
switch_cover_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
library switch_cover_button;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class SwitchCoverButton extends StatefulWidget {
final bool switchValue;
final ValueChanged<bool> onChanged;
final double size;
final Color activeThumbColor;
final Color inactiveThumbColor;
final Color inactiveTrackColor;
const SwitchCoverButton({
required Key key,
required this.switchValue,
required this.onChanged,
this.size = 2,
this.activeThumbColor = Colors.blue,
this.inactiveThumbColor = Colors.white,
this.inactiveTrackColor = Colors.black12,
}) : super(key: key);
@override
SwitchCoverButtonState createState() => SwitchCoverButtonState();
}
class SwitchCoverButtonState extends State<SwitchCoverButton>
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: CupertinoSwitch(
onChanged: toggleSwitch,
value: widget.switchValue,
activeColor: widget.activeThumbColor,
trackColor: widget.inactiveTrackColor,
thumbColor: widget.inactiveThumbColor,
),
),
]);
}
}