@@ -8,16 +8,33 @@ import 'material_switch.dart';
8
8
9
9
const _sizeAndroid = Size (48 , 24 );
10
10
const _sizeIOS = Size (56 , 32 );
11
+ const _sizeWeb = Size (64 , 32 );
12
+
13
+ /// Variants of [ZetaSwitch] .
14
+ enum ZetaSwitchType {
15
+ /// 64 x 32
16
+ web,
17
+
18
+ /// 48 x 24
19
+ android,
20
+
21
+ /// 56 x 32
22
+ ios,
23
+ }
11
24
12
25
/// Zeta Switch.
13
26
///
14
27
/// Switch can turn an option on or off.
28
+ ///
29
+ /// Switch has styles for Android, iOS and Web.
30
+ // TODO(switch): Add web icon support.
15
31
class ZetaSwitch extends StatelessWidget {
16
32
/// Constructor for [ZetaSwitch] .
17
33
const ZetaSwitch ({
18
34
super .key,
19
35
this .value = false ,
20
36
this .onChanged,
37
+ this .variant,
21
38
});
22
39
23
40
/// Determines whether the switch is on or off.
@@ -26,19 +43,44 @@ class ZetaSwitch extends StatelessWidget {
26
43
/// Called when the value of the switch should change.
27
44
final ValueChanged <bool ?>? onChanged;
28
45
46
+ /// Variant of switch for different platforms.
47
+ ///
48
+ /// Defaults to match the platform, or falls back to web.
49
+ final ZetaSwitchType ? variant;
50
+
29
51
@override
30
52
void debugFillProperties (DiagnosticPropertiesBuilder properties) {
31
53
super .debugFillProperties (properties);
32
54
properties
33
55
..add (FlagProperty ('value' , value: value, ifTrue: 'on' , ifFalse: 'off' , showName: true ))
34
- ..add (ObjectFlagProperty <ValueChanged <bool >>('onChanged' , onChanged, ifNull: 'disabled' ));
56
+ ..add (ObjectFlagProperty <ValueChanged <bool >>('onChanged' , onChanged, ifNull: 'disabled' ))
57
+ ..add (EnumProperty <ZetaSwitchType ?>('variant' , variant));
58
+ }
59
+
60
+ ZetaSwitchType get _variant {
61
+ if (variant != null ) return variant! ;
62
+ if (kIsWeb) return ZetaSwitchType .web;
63
+ return switch (Platform .operatingSystem) {
64
+ 'ios' => ZetaSwitchType .ios,
65
+ 'android' => ZetaSwitchType .android,
66
+ _ => ZetaSwitchType .web,
67
+ };
68
+ }
69
+
70
+ Size get _size {
71
+ return switch (_variant) {
72
+ ZetaSwitchType .ios => _sizeIOS,
73
+ ZetaSwitchType .android => _sizeAndroid,
74
+ _ => _sizeWeb,
75
+ };
35
76
}
36
77
37
78
@override
38
79
Widget build (BuildContext context) {
39
80
final zetaColors = Zeta .of (context).colors;
81
+
40
82
return MaterialSwitch (
41
- size: Platform .isIOS ? _sizeIOS : _sizeAndroid ,
83
+ size: _size ,
42
84
trackOutlineWidth: const MaterialStatePropertyAll (0 ),
43
85
trackOutlineColor: const MaterialStatePropertyAll (Colors .transparent),
44
86
trackColor: MaterialStateProperty .resolveWith ((states) {
@@ -53,6 +95,7 @@ class ZetaSwitch extends StatelessWidget {
53
95
),
54
96
value: value ?? false ,
55
97
onChanged: onChanged,
98
+ thumbSize: _variant == ZetaSwitchType .web ? const Size .square (ZetaSpacing .m) : null ,
56
99
);
57
100
}
58
101
}
0 commit comments