5
5
import 'template.dart' ;
6
6
7
7
class SegmentedButtonTemplate extends TokenTemplate {
8
- const SegmentedButtonTemplate (super .blockName, super .fileName, super .tokens, {
8
+ const SegmentedButtonTemplate (this .tokenGroup, super .blockName, super .fileName, super .tokens, {
9
9
super .colorSchemePrefix = '_colors.' ,
10
10
});
11
11
12
+ final String tokenGroup;
13
+
12
14
String _layerOpacity (String layerToken) {
13
15
if (tokens.containsKey (layerToken)) {
14
16
final String ? layerValue = tokens[layerToken] as String ? ;
@@ -33,90 +35,88 @@ class SegmentedButtonTemplate extends TokenTemplate {
33
35
34
36
@override
35
37
String generate () => '''
36
- class _SegmentedButtonDefaultsM3 extends SegmentedButtonThemeData {
37
- _SegmentedButtonDefaultsM3(this.context);
38
-
38
+ class _${blockName }DefaultsM3 extends SegmentedButtonThemeData {
39
+ _${blockName }DefaultsM3(this.context);
39
40
final BuildContext context;
40
41
late final ThemeData _theme = Theme.of(context);
41
42
late final ColorScheme _colors = _theme.colorScheme;
42
-
43
43
@override ButtonStyle? get style {
44
44
return ButtonStyle(
45
- textStyle: MaterialStatePropertyAll<TextStyle?>(${textStyle ('md.comp.outlined-segmented-button .label-text' )}),
45
+ textStyle: MaterialStatePropertyAll<TextStyle?>(${textStyle ('$ tokenGroup .label-text' )}),
46
46
backgroundColor: MaterialStateProperty.resolveWith((Set<MaterialState> states) {
47
47
if (states.contains(MaterialState.disabled)) {
48
- return ${componentColor ('md.comp.outlined-segmented-button .disabled' )};
48
+ return ${componentColor ('$ tokenGroup .disabled' )};
49
49
}
50
50
if (states.contains(MaterialState.selected)) {
51
- return ${componentColor ('md.comp.outlined-segmented-button .selected.container' )};
51
+ return ${componentColor ('$ tokenGroup .selected.container' )};
52
52
}
53
- return ${componentColor ('md.comp.outlined-segmented-button .unselected.container' )};
53
+ return ${componentColor ('$ tokenGroup .unselected.container' )};
54
54
}),
55
55
foregroundColor: MaterialStateProperty.resolveWith((Set<MaterialState> states) {
56
56
if (states.contains(MaterialState.disabled)) {
57
- return ${componentColor ('md.comp.outlined-segmented-button .disabled.label-text' )};
57
+ return ${componentColor ('$ tokenGroup .disabled.label-text' )};
58
58
}
59
59
if (states.contains(MaterialState.selected)) {
60
60
if (states.contains(MaterialState.pressed)) {
61
- return ${componentColor ('md.comp.outlined-segmented-button .selected.pressed.label-text' )};
61
+ return ${componentColor ('$ tokenGroup .selected.pressed.label-text' )};
62
62
}
63
63
if (states.contains(MaterialState.hovered)) {
64
- return ${componentColor ('md.comp.outlined-segmented-button .selected.hover.label-text' )};
64
+ return ${componentColor ('$ tokenGroup .selected.hover.label-text' )};
65
65
}
66
66
if (states.contains(MaterialState.focused)) {
67
- return ${componentColor ('md.comp.outlined-segmented-button .selected.focus.label-text' )};
67
+ return ${componentColor ('$ tokenGroup .selected.focus.label-text' )};
68
68
}
69
- return ${componentColor ('md.comp.outlined-segmented-button .selected.label-text' )};
69
+ return ${componentColor ('$ tokenGroup .selected.label-text' )};
70
70
} else {
71
71
if (states.contains(MaterialState.pressed)) {
72
- return ${componentColor ('md.comp.outlined-segmented-button .unselected.pressed.label-text' )};
72
+ return ${componentColor ('$ tokenGroup .unselected.pressed.label-text' )};
73
73
}
74
74
if (states.contains(MaterialState.hovered)) {
75
- return ${componentColor ('md.comp.outlined-segmented-button .unselected.hover.label-text' )};
75
+ return ${componentColor ('$ tokenGroup .unselected.hover.label-text' )};
76
76
}
77
77
if (states.contains(MaterialState.focused)) {
78
- return ${componentColor ('md.comp.outlined-segmented-button .unselected.focus.label-text' )};
78
+ return ${componentColor ('$ tokenGroup .unselected.focus.label-text' )};
79
79
}
80
- return ${componentColor ('md.comp.outlined-segmented-button. unselected.container ' )};
80
+ return ${componentColor ('$ tokenGroup . unselected.label-text ' )};
81
81
}
82
82
}),
83
83
overlayColor: MaterialStateProperty.resolveWith((Set<MaterialState> states) {
84
84
if (states.contains(MaterialState.selected)) {
85
85
if (states.contains(MaterialState.hovered)) {
86
- return ${_stateColor ('md.comp.outlined-segmented-button' , 'selected' , 'hover' )};
86
+ return ${_stateColor (tokenGroup , 'selected' , 'hover' )};
87
87
}
88
88
if (states.contains(MaterialState.focused)) {
89
- return ${_stateColor ('md.comp.outlined-segmented-button' , 'selected' , 'focus' )};
89
+ return ${_stateColor (tokenGroup , 'selected' , 'focus' )};
90
90
}
91
91
if (states.contains(MaterialState.pressed)) {
92
- return ${_stateColor ('md.comp.outlined-segmented-button' , 'selected' , 'pressed' )};
92
+ return ${_stateColor (tokenGroup , 'selected' , 'pressed' )};
93
93
}
94
94
} else {
95
95
if (states.contains(MaterialState.hovered)) {
96
- return ${_stateColor ('md.comp.outlined-segmented-button' , 'unselected' , 'hover' )};
96
+ return ${_stateColor (tokenGroup , 'unselected' , 'hover' )};
97
97
}
98
98
if (states.contains(MaterialState.focused)) {
99
- return ${_stateColor ('md.comp.outlined-segmented-button' , 'unselected' , 'focus' )};
99
+ return ${_stateColor (tokenGroup , 'unselected' , 'focus' )};
100
100
}
101
101
if (states.contains(MaterialState.pressed)) {
102
- return ${_stateColor ('md.comp.outlined-segmented-button' , 'unselected' , 'pressed' )};
102
+ return ${_stateColor (tokenGroup , 'unselected' , 'pressed' )};
103
103
}
104
104
}
105
105
return null;
106
106
}),
107
107
surfaceTintColor: const MaterialStatePropertyAll<Color>(Colors.transparent),
108
108
elevation: const MaterialStatePropertyAll<double>(0),
109
- iconSize: const MaterialStatePropertyAll<double?>(${tokens ['md.comp.outlined-segmented-button .with-icon.icon.size' ]}),
109
+ iconSize: const MaterialStatePropertyAll<double?>(${tokens ['$ tokenGroup .with-icon.icon.size' ]}),
110
110
side: MaterialStateProperty.resolveWith((Set<MaterialState> states) {
111
111
if (states.contains(MaterialState.disabled)) {
112
- return ${border ("md.comp.outlined-segmented-button .disabled.outline" )};
112
+ return ${border ("$ tokenGroup .disabled.outline" )};
113
113
}
114
- return ${border ("md.comp.outlined-segmented-button .outline" )};
114
+ return ${border ("$ tokenGroup .outline" )};
115
115
}),
116
- shape: const MaterialStatePropertyAll<OutlinedBorder>(${shape ("md.comp.outlined-segmented-button" , '' )}),
116
+ shape: const MaterialStatePropertyAll<OutlinedBorder>(${shape (tokenGroup , '' )}),
117
+ minimumSize: const MaterialStatePropertyAll<Size?>(Size.fromHeight(${tokens ['$tokenGroup .container.height' ]})),
117
118
);
118
119
}
119
-
120
120
@override
121
121
Widget? get selectedIcon => const Icon(Icons.check);
122
122
}
0 commit comments