forked from bdlukaa/fluent_ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pickers.dart
198 lines (183 loc) · 5.1 KB
/
pickers.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import 'package:fluent_ui/fluent_ui.dart';
const kPickerContentPadding = EdgeInsets.symmetric(
horizontal: 8.0,
vertical: 4.0,
);
const kPickerHeight = 32.0;
const kPickerDiameterRatio = 100.0;
const kPopupHeight = kOneLineTileHeight * 10;
BoxDecoration kPickerBackgroundDecoration(BuildContext context) =>
BoxDecoration(
color: context.theme.acrylicBackgroundColor,
borderRadius: BorderRadius.circular(4.0),
border: Border.all(
color: context.theme.scaffoldBackgroundColor,
width: 0.6,
),
);
TextStyle? kPickerPopupTextStyle(BuildContext context) {
return context.theme.typography.body?.copyWith(fontSize: 16);
}
Decoration kPickerDecorationBuilder(BuildContext context, List<ButtonStates> states) {
assert(debugCheckHasFluentTheme(context));
return BoxDecoration(
borderRadius: BorderRadius.circular(4.0),
border: Border.all(
color: () {
late Color color;
if (states.isHovering) {
color = context.theme.inactiveColor;
} else if (states.isDisabled) {
color = context.theme.disabledColor;
} else {
color = context.theme.inactiveColor.withOpacity(0.75);
}
return color;
}(),
width: 1.0,
),
color: () {
if (states.isPressing)
return context.theme.disabledColor.withOpacity(0.2);
else if (states.isFocused) {
return context.theme.disabledColor.withOpacity(0.2);
}
}(),
);
}
class YesNoPickerControl extends StatelessWidget {
const YesNoPickerControl({
Key? key,
required this.onChanged,
required this.onCancel,
}) : super(key: key);
final VoidCallback onChanged;
final VoidCallback onCancel;
@override
Widget build(BuildContext context) {
assert(debugCheckHasFluentTheme(context));
ButtonThemeData style(BorderRadiusGeometry radius) {
return ButtonThemeData(
margin: EdgeInsets.zero,
decoration: (state) => BoxDecoration(
color: ButtonThemeData.uncheckedInputColor(context.theme, state),
borderRadius: radius,
),
scaleFactor: 1.0,
);
}
return Row(children: [
Expanded(
child: SizedBox(
height: kOneLineTileHeight,
child: Button(
child: Icon(Icons.check),
onPressed: onChanged,
style: style(BorderRadius.only(
bottomLeft: Radius.circular(4.0),
)),
),
),
),
Expanded(
child: SizedBox(
height: kOneLineTileHeight,
child: Button(
child: Icon(Icons.close),
onPressed: onCancel,
style: style(BorderRadius.only(
bottomRight: Radius.circular(4.0),
)),
),
),
),
]);
}
}
class PickerNavigatorIndicator extends StatelessWidget {
const PickerNavigatorIndicator({
Key? key,
required this.child,
required this.onBackward,
required this.onForward,
}) : super(key: key);
final Widget child;
final VoidCallback onForward;
final VoidCallback onBackward;
@override
Widget build(BuildContext context) {
assert(debugCheckHasFluentTheme(context));
final style = ButtonThemeData(
padding: EdgeInsets.all(2.0),
margin: EdgeInsets.zero,
scaleFactor: 1.0,
decoration: (state) {
return BoxDecoration(
borderRadius: BorderRadius.circular(4.0),
color: ButtonThemeData.buttonColor(context.theme, state),
);
},
);
return HoverButton(
onPressed: () {},
builder: (context, state) {
final isHovering =
state.isHovering || state.isPressing || state.isFocused;
return Stack(children: [
child,
if (isHovering)
Positioned(
top: 0,
left: 0,
right: 0,
child: Button(
child: Center(child: Icon(Icons.keyboard_arrow_up, size: 14)),
onPressed: onBackward,
style: style,
),
),
if (isHovering)
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Button(
child: Center(child: Icon(Icons.keyboard_arrow_down, size: 14)),
onPressed: onForward,
style: style,
),
),
]);
},
);
}
}
void navigateSides(
BuildContext context,
FixedExtentScrollController controller,
bool forward,
int amount,
) {
assert(debugCheckHasFluentTheme(context));
final duration = context.theme.fasterAnimationDuration;
final curve = context.theme.animationCurve;
if (forward) {
final currentItem = controller.selectedItem;
int to = currentItem + 1;
if (currentItem == amount - 1) to = 0;
controller.animateToItem(
to,
duration: duration,
curve: curve,
);
} else {
final currentItem = controller.selectedItem;
int to = currentItem - 1;
if (currentItem == 0) to = amount - 1;
controller.animateToItem(
to,
duration: duration,
curve: curve,
);
}
}