-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
color_picker_screen.dart
354 lines (342 loc) · 11.9 KB
/
color_picker_screen.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
import 'package:color_picker_example/demo/screens/color_picker/picker_indicators/premade_dialog_picker_color_indicator.dart';
import 'package:flutter/material.dart';
import '../../utils/app.dart';
import '../../widgets/flex_app_bar.dart';
import 'about.dart';
import 'all_control_widgets.dart';
import 'color_picker_card.dart';
import 'picker_switches/dialog_action_only_ok_button_switch.dart';
import 'picker_text_fields/text_field_focus_demo.dart';
import 'picker_toggle_buttons/actions_order_switch.dart';
/// Screen with the two ColorPickers and all controls and settings we use to
/// manipulate their design and behavior.
///
/// The layout is responsive and can have 1 to 4 columns that contains the
/// ColorPicker and the controls, each column when visible has its own
/// ListView, so the columns can be scrolled individually when they are visible.
class ColorPickerScreen extends StatelessWidget {
const ColorPickerScreen({super.key});
@override
Widget build(BuildContext context) {
// Used for a simple scrollable column based responsive layout
final double width = MediaQuery.sizeOf(context).width;
// That can have 1 to max 4 columns
int columns = width ~/ App.minColumnWidth;
if (columns < 1) columns = 1;
if (columns > 4) columns = 4;
// ScrollControllers for potential 4 List views
final ScrollController scrollOne = ScrollController();
final ScrollController scrollTwo = ScrollController();
final ScrollController scrollThree = ScrollController();
final ScrollController scrollFour = ScrollController();
return Scaffold(
extendBodyBehindAppBar: true,
appBar: FlexAppBar.styled(
context,
centerTitle: true,
title: const Text('FlexColorPicker Demo'),
actions: const <Widget>[AboutIconButton()],
blurred: true,
opacity: 0.5,
gradient: false,
hasBorderOnSurface: true,
scrim: false,
).toAppBar(),
body: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: App.maxBodyWidth),
child: Row(
// The Row contains 1 to 4 ListViews, each in an Expanded widget.
//
// Based on width, the 1st one can contain, col 1, 1+2 or 1+2+3+4
children: <Widget>[
Expanded(
child: Scrollbar(
controller: scrollOne,
thumbVisibility: true,
interactive: true,
child: ListView(
controller: scrollOne,
padding: const EdgeInsets.fromLTRB(8, 0, 8, 0),
children: <Widget>[
SizedBox(
height: MediaQuery.of(context).padding.top +
kToolbarHeight),
const _Column1(),
if (columns < 3) const _Column2(),
if (columns < 2) const _Column3(),
if (columns < 2) const _Column4(),
],
),
),
),
//
// Based on width, the 2nd one can contain, col 3+4 or col 2,
// when we have 2 columns or more.
if (columns > 1)
Expanded(
child: Scrollbar(
controller: scrollTwo,
thumbVisibility: true,
interactive: true,
child: ListView(
controller: scrollTwo,
padding: const EdgeInsets.fromLTRB(8, 0, 8, 0),
children: <Widget>[
SizedBox(
height: MediaQuery.of(context).padding.top +
kToolbarHeight),
if (columns == 3 || columns == 4) const _Column2(),
if (columns < 3) const _Column3(),
if (columns < 3) const _Column4(),
],
),
),
),
//
// Based on width, the 3rd one can contain, col 3 or col 3+4,
// when we have 3 columns or more.
if (columns > 2)
Expanded(
child: Scrollbar(
controller: scrollThree,
thumbVisibility: true,
interactive: true,
child: ListView(
controller: scrollThree,
padding: const EdgeInsets.fromLTRB(8, 0, 8, 0),
children: <Widget>[
SizedBox(
height: MediaQuery.of(context).padding.top +
kToolbarHeight),
// Show the selected color in a dialog
const _Column3(),
if (columns < 4) const _Column4(),
],
),
),
),
//
// The 4th one only shows the 4th column when we have 4 columns.
if (columns > 3)
Expanded(
child: Scrollbar(
controller: scrollFour,
thumbVisibility: true,
interactive: true,
child: ListView(
controller: scrollFour,
padding: const EdgeInsets.fromLTRB(8, 0, 8, 0),
children: <Widget>[
SizedBox(
height: MediaQuery.of(context).padding.top +
kToolbarHeight),
const _Column4(),
],
),
),
),
],
),
),
),
);
}
}
class _Column1 extends StatelessWidget {
const _Column1();
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 0, 14),
child: Text(
'FlexColorPicker',
style: Theme.of(context).textTheme.headlineMedium,
),
),
// Show the color selected in a dialog and open a dialog to change it.
const DialogPickerColorIndicator(),
const PremadeDialogPickerColorIndicator(),
// Show the color selected in the picker in a Card below.
const CardPickerColorIndicator(),
// Show the picker meta remote control widget.
const MetaPickerColorIndicator(),
// The color picker in a Card.
const Padding(
padding: EdgeInsets.all(6),
child: ColorPickerCard(),
),
const ListTile(
subtitle: Wrap(runSpacing: 8, children: <Widget>[
OnStartColorIndicator(),
SizedBox(width: 8),
OnChangedColorIndicator(),
SizedBox(width: 8),
OnEndColorIndicator(),
]),
),
const ListTile(
title: Text('Color change callbacks'),
subtitle: Text('Above callbacks are color before change started, '
'during change and when change ended.'),
),
const Divider(),
const CopyFormatSwitch(),
const SizedBox(height: 8),
const ListTile(
title: Text('Select and COPY a color value. PASTE it into the picker '
'with toolbar buttons, context menu or keyboard shortcuts.\n'
'Try these:'),
subtitle: SelectableText('Primary FF7B1FA2 Accent FFCCFF90 '
'BW FFF9F9F9\n'
'Custom #014443 Wheel 0xFF6E55C4 ShortWeb 5EC\n'
'Partial #DDFF Opacity #99FF9800 Fail 94G02\n'
'PASTE supports all above formats. COPY in selected format.'),
),
const ParseShortHexCodeSwitch(),
const Divider(),
const TextFieldFocusDemo(),
const PickerAutoFocusSwitch(),
const Divider(),
],
);
}
}
class _Column2 extends StatelessWidget {
const _Column2();
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 0, 14),
child: Text(
'Show and hide',
style: Theme.of(context).textTheme.headlineMedium,
),
),
//
const PickersEnabledSwitch(),
const SizedBox(height: 8),
const ShadesSwitch(),
const Index850Switch(),
const TonalSwitch(),
const OpacitySwitch(),
const Divider(),
//
const MaterialNameSwitch(),
const ColorNameSwitch(),
const ColorCodeSwitch(),
const ColorCodeHasColorSwitch(),
const ColorCodeReadOnlySwitch(),
const ColorValueSwitch(),
const RecentColorsSwitch(),
const Divider(),
//
const TitleSwitch(),
const HeadingSwitch(),
const SubheadingSwitch(),
const TonalSubheadingSwitch(),
const OpacitySubheadingSwitch(),
const RecentSubheadingSwitch(),
const Divider(),
],
);
}
}
class _Column3 extends StatelessWidget {
const _Column3();
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 0, 14),
child: Text(
'Picker design',
style: Theme.of(context).textTheme.headlineMedium,
),
),
// Color picker size
const ItemSizeSlider(),
const TonalSameSizeSwitch(),
const BorderRadiusSlider(),
const ElevationSlider(),
const SpacingSlider(),
const RunSpacingSlider(),
const HasBorderSwitch(),
const Divider(),
//
const WheelDiameterSlider(),
const WheelWidthSlider(),
const WheelSquarePaddingSlider(),
const WheelSquareBorderRadiusSlider(),
const WheelHasBorderSwitch(),
const Divider(),
//
const OpacityTrackHeightSlider(),
const OpacityTrackWidthSlider(),
const OpacityThumbRadiusSlider(),
const Divider(),
//
const EnableTooltipsSwitch(),
const Divider(),
],
);
}
}
class _Column4 extends StatelessWidget {
const _Column4();
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 0, 14),
child: Text(
'Picker layout',
style: Theme.of(context).textTheme.headlineMedium,
),
),
const AlignmentSwitch(),
const ColumnSpacingSlider(),
const PaddingSlider(),
const CloseButtonSwitch(),
const OkButtonSwitch(),
const CloseIsLastSwitch(),
const DialogActionsButtonsSwitch(),
const DialogActionOnlyOkButtonSwitch(),
const ActionsOrderSwitch(),
const DialogActionIconsSwitch(),
const Divider(),
//
Padding(
padding: const EdgeInsets.fromLTRB(16, 4, 0, 14),
child: Text(
'Copy paste actions',
style: Theme.of(context).textTheme.headlineMedium,
),
),
const ControlCopySwitch(),
const ControlPasteSwitch(),
const ToolbarCopySwitch(),
const ToolbarPasteSwitch(),
const EditFieldCopySwitch(),
const SecondaryMenuSwitch(),
const LongPressMenuSwitch(),
const SecondaryDesktopLongDeviceSwitch(),
const SecondaryDesktopLongWebDeviceSwitch(),
const EditUsesParsedPasteSwitch(),
const SnackbarParseErrorSwitch(),
const FeedbackParseErrorSwitch(),
const Divider(),
],
);
}
}