forked from flutter/devtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon_widgets.dart
More file actions
1905 lines (1653 loc) · 48.6 KB
/
common_widgets.dart
File metadata and controls
1905 lines (1653 loc) · 48.6 KB
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:convert';
import 'dart:math';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'analytics/analytics.dart' as ga;
import 'auto_dispose_mixin.dart';
import 'config_specific/launch_url/launch_url.dart';
import 'flutter_widgets/linked_scroll_controller.dart';
import 'globals.dart';
import 'scaffold.dart';
import 'theme.dart';
import 'ui/icons.dart';
import 'ui/label.dart';
import 'utils.dart';
const tooltipWait = Duration(milliseconds: 500);
const tooltipWaitLong = Duration(milliseconds: 1000);
/// The width of the package:flutter_test debugger device.
const debuggerDeviceWidth = 800.0;
const mediumDeviceWidth = 1000.0;
const defaultDialogRadius = 20.0;
double get areaPaneHeaderHeight => scaleByFontFactor(36.0);
/// Convenience [Divider] with [Padding] that provides a good divider in forms.
class PaddedDivider extends StatelessWidget {
const PaddedDivider({
Key key,
this.padding = const EdgeInsets.only(bottom: 10.0),
}) : super(key: key);
const PaddedDivider.thin({Key key})
: padding = const EdgeInsets.only(bottom: 4.0);
PaddedDivider.vertical({Key key, double padding = densePadding})
: padding = EdgeInsets.symmetric(vertical: padding);
/// The padding to place around the divider.
final EdgeInsets padding;
@override
Widget build(BuildContext context) {
return Padding(
padding: padding,
child: const Divider(thickness: 1.0),
);
}
}
/// Creates a semibold version of [style].
TextStyle semibold(TextStyle style) =>
style.copyWith(fontWeight: FontWeight.w600);
/// Creates a version of [style] that uses the primary color of [context].
///
/// When the app is in dark mode, it instead uses the accent color.
TextStyle primaryColor(TextStyle style, BuildContext context) {
final theme = Theme.of(context);
return style.copyWith(
color: (theme.brightness == Brightness.light)
? theme.primaryColor
: theme.colorScheme.secondary,
fontWeight: FontWeight.w400,
);
}
/// Creates a version of [style] that uses the lighter primary color of
/// [context].
///
/// In dark mode, the light primary color still has enough contrast to be
/// visible, so we continue to use it.
TextStyle primaryColorLight(TextStyle style, BuildContext context) {
final theme = Theme.of(context);
return style.copyWith(
color: theme.primaryColorLight,
fontWeight: FontWeight.w300,
);
}
class OutlinedIconButton extends IconLabelButton {
const OutlinedIconButton({
@required IconData icon,
@required VoidCallback onPressed,
String tooltip,
}) : super(
icon: icon,
label: '',
tooltip: tooltip,
onPressed: onPressed,
// TODO(jacobr): consider a more conservative min-width. To minimize the
// impact on the existing UI and deal with the fact that some of the
// existing label names are fairly verbose, we set a width that will
// never be hit.
minScreenWidthForTextBeforeScaling: 20000,
);
}
/// A button with an icon and a label.
///
/// * `onPressed`: The callback to be called upon pressing the button.
/// * `minScreenWidthForTextBeforeScaling`: The minimum width the button can be before the text is
/// omitted.
class IconLabelButton extends StatelessWidget {
const IconLabelButton({
Key key,
this.icon,
this.imageIcon,
@required this.label,
@required this.onPressed,
this.color,
this.minScreenWidthForTextBeforeScaling,
this.elevatedButton = false,
this.tooltip,
this.tooltipPadding,
this.outlined = true,
}) : assert((icon == null) != (imageIcon == null)),
super(key: key);
final IconData icon;
final ThemedImageIcon imageIcon;
final String label;
final double minScreenWidthForTextBeforeScaling;
final VoidCallback onPressed;
final Color color;
/// Whether this icon label button should use an elevated button style.
final bool elevatedButton;
final String tooltip;
final EdgeInsetsGeometry tooltipPadding;
final bool outlined;
@override
Widget build(BuildContext context) {
final iconLabel = MaterialIconLabel(
label: label,
iconData: icon,
imageIcon: imageIcon,
minScreenWidthForTextBeforeScaling: minScreenWidthForTextBeforeScaling,
color: color,
);
if (elevatedButton) {
return maybeWrapWithTooltip(
tooltip: tooltip,
tooltipPadding: tooltipPadding,
child: ElevatedButton(
onPressed: onPressed,
child: iconLabel,
),
);
}
// TODO(kenz): this SizedBox wrapper should be unnecessary once
// https://github.com/flutter/flutter/issues/79894 is fixed.
return maybeWrapWithTooltip(
tooltip: tooltip,
tooltipPadding: tooltipPadding,
child: SizedBox(
height: defaultButtonHeight,
width: !includeText(context, minScreenWidthForTextBeforeScaling)
? buttonMinWidth
: null,
child: outlined
? OutlinedButton(
style: denseAwareOutlinedButtonStyle(
context,
minScreenWidthForTextBeforeScaling,
),
onPressed: onPressed,
child: iconLabel,
)
: TextButton(
onPressed: onPressed,
child: iconLabel,
style: denseAwareOutlinedButtonStyle(
context,
minScreenWidthForTextBeforeScaling,
),
),
),
);
}
}
class PauseButton extends IconLabelButton {
const PauseButton({
Key key,
double minScreenWidthForTextBeforeScaling,
String tooltip = 'Pause',
@required VoidCallback onPressed,
}) : super(
key: key,
icon: Icons.pause,
label: 'Pause',
tooltip: tooltip,
minScreenWidthForTextBeforeScaling:
minScreenWidthForTextBeforeScaling,
onPressed: onPressed,
);
}
class ResumeButton extends IconLabelButton {
const ResumeButton({
Key key,
double minScreenWidthForTextBeforeScaling,
String tooltip = 'Resume',
@required VoidCallback onPressed,
}) : super(
key: key,
icon: Icons.play_arrow,
label: 'Resume',
tooltip: tooltip,
minScreenWidthForTextBeforeScaling:
minScreenWidthForTextBeforeScaling,
onPressed: onPressed,
);
}
class ClearButton extends IconLabelButton {
const ClearButton({
Key key,
double minScreenWidthForTextBeforeScaling,
String tooltip = 'Clear',
@required VoidCallback onPressed,
}) : super(
key: key,
icon: Icons.block,
label: 'Clear',
tooltip: tooltip,
minScreenWidthForTextBeforeScaling:
minScreenWidthForTextBeforeScaling,
onPressed: onPressed,
);
}
class RefreshButton extends IconLabelButton {
const RefreshButton({
Key key,
String label = 'Refresh',
double minScreenWidthForTextBeforeScaling,
String tooltip,
@required VoidCallback onPressed,
}) : super(
key: key,
icon: Icons.refresh,
label: label,
minScreenWidthForTextBeforeScaling:
minScreenWidthForTextBeforeScaling,
tooltip: tooltip,
onPressed: onPressed,
);
}
/// Button to start recording data.
///
/// * `recording`: Whether recording is in progress.
/// * `minScreenWidthForTextBeforeScaling`: The minimum width the button can be before the text is
/// omitted.
/// * `labelOverride`: Optional alternative text to use for the button.
/// * `onPressed`: The callback to be called upon pressing the button.
class RecordButton extends IconLabelButton {
const RecordButton({
Key key,
@required bool recording,
@required VoidCallback onPressed,
double minScreenWidthForTextBeforeScaling,
String labelOverride,
String tooltip = 'Start recording',
}) : super(
key: key,
onPressed: recording ? null : onPressed,
icon: Icons.fiber_manual_record,
label: labelOverride ?? 'Record',
tooltip: tooltip,
minScreenWidthForTextBeforeScaling:
minScreenWidthForTextBeforeScaling,
);
}
/// Button to stop recording data.
///
/// * `recording`: Whether recording is in progress.
/// * `minScreenWidthForTextBeforeScaling`: The minimum width the button can be before the text is
/// omitted.
/// * `onPressed`: The callback to be called upon pressing the button.
class StopRecordingButton extends IconLabelButton {
const StopRecordingButton({
Key key,
@required bool recording,
@required VoidCallback onPressed,
double minScreenWidthForTextBeforeScaling,
String tooltip = 'Stop recording',
}) : super(
key: key,
onPressed: !recording ? null : onPressed,
icon: Icons.stop,
label: 'Stop',
tooltip: tooltip,
minScreenWidthForTextBeforeScaling:
minScreenWidthForTextBeforeScaling,
);
}
class SettingsOutlinedButton extends OutlinedIconButton {
const SettingsOutlinedButton({
@required VoidCallback onPressed,
@required String label,
String tooltip,
}) : super(
onPressed: onPressed,
icon: Icons.settings,
tooltip: tooltip,
);
}
class HelpButton extends StatelessWidget {
const HelpButton({
@required this.onPressed,
@required this.gaScreen,
@required this.gaSelection,
});
final VoidCallback onPressed;
final String gaScreen;
final String gaSelection;
@override
Widget build(BuildContext context) {
return DevToolsIconButton(
iconData: Icons.help_outline,
onPressed: onPressed,
tooltip: 'Help',
gaScreen: gaScreen,
gaSelection: gaSelection,
);
}
}
class ExpandAllButton extends StatelessWidget {
const ExpandAllButton({Key key, @required this.onPressed}) : super(key: key);
final VoidCallback onPressed;
@override
Widget build(BuildContext context) {
return OutlinedButton(
onPressed: onPressed,
child: const Text('Expand All'),
);
}
}
class CollapseAllButton extends StatelessWidget {
const CollapseAllButton({Key key, @required this.onPressed})
: super(key: key);
final VoidCallback onPressed;
@override
Widget build(BuildContext context) {
return OutlinedButton(
onPressed: onPressed,
child: const Text('Collapse All'),
);
}
}
class RecordingInfo extends StatelessWidget {
const RecordingInfo({
this.instructionsKey,
this.recordingStatusKey,
this.processingStatusKey,
@required this.recording,
@required this.recordedObject,
@required this.processing,
this.progressValue,
this.isPause = false,
});
final Key instructionsKey;
final Key recordingStatusKey;
final Key processingStatusKey;
final bool recording;
final String recordedObject;
final bool processing;
final double progressValue;
final bool isPause;
@override
Widget build(BuildContext context) {
Widget child;
if (processing) {
child = ProcessingInfo(
key: processingStatusKey,
progressValue: progressValue,
processedObject: recordedObject,
);
} else if (recording) {
child = RecordingStatus(
key: recordingStatusKey,
recordedObject: recordedObject,
);
} else {
child = RecordingInstructions(
key: instructionsKey,
recordedObject: recordedObject,
isPause: isPause,
);
}
return Center(
child: child,
);
}
}
class RecordingStatus extends StatelessWidget {
const RecordingStatus({
Key key,
@required this.recordedObject,
}) : super(key: key);
final String recordedObject;
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Recording $recordedObject',
style: Theme.of(context).subtleTextStyle,
),
const SizedBox(height: defaultSpacing),
const CircularProgressIndicator(),
],
);
}
}
class RecordingInstructions extends StatelessWidget {
const RecordingInstructions({
Key key,
@required this.isPause,
@required this.recordedObject,
}) : super(key: key);
final String recordedObject;
final bool isPause;
@override
Widget build(BuildContext context) {
final stopOrPauseRow = Row(
mainAxisAlignment: MainAxisAlignment.center,
children: isPause
? const [
Text('Click the pause button '),
Icon(Icons.pause),
Text(' to pause the recording.'),
]
: const [
Text('Click the stop button '),
Icon(Icons.stop),
Text(' to end the recording.'),
],
);
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('Click the record button '),
const Icon(Icons.fiber_manual_record),
Text(' to start recording $recordedObject.')
],
),
stopOrPauseRow,
],
);
}
}
class ProcessingInfo extends StatelessWidget {
const ProcessingInfo({
Key key,
@required this.progressValue,
@required this.processedObject,
}) : super(key: key);
final double progressValue;
final String processedObject;
@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Processing $processedObject',
style: Theme.of(context).subtleTextStyle,
),
const SizedBox(height: defaultSpacing),
SizedBox(
width: 200.0,
height: defaultSpacing,
child: LinearProgressIndicator(
value: progressValue,
),
),
],
),
);
}
}
/// Common button for exiting offline mode.
///
/// Consumers of this widget will be responsible for including the following in
/// onPressed:
///
/// setState(() {
/// offlineController.exitOfflineMode();
/// }
class ExitOfflineButton extends IconLabelButton {
const ExitOfflineButton({@required VoidCallback onPressed})
: super(
key: const Key('exit offline button'),
onPressed: onPressed,
label: 'Exit offline mode',
icon: Icons.clear,
);
}
/// Display a single bullet character in order to act as a stylized spacer
/// component.
class BulletSpacer extends StatelessWidget {
const BulletSpacer({this.useAccentColor = false});
final bool useAccentColor;
static double get width => DevToolsScaffold.actionWidgetSize / 2;
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
TextStyle textStyle;
if (useAccentColor) {
textStyle = theme.appBarTheme.toolbarTextStyle ??
theme.primaryTextTheme.bodyText2;
} else {
textStyle = theme.textTheme.bodyText2;
}
final mutedColor = textStyle?.color?.withAlpha(0x90);
return Container(
width: width,
height: DevToolsScaffold.actionWidgetSize,
alignment: Alignment.center,
child: Text(
'•',
style: textStyle?.copyWith(color: mutedColor),
),
);
}
}
/// A small element containing some accessory information, often a numeric
/// value.
class Badge extends StatelessWidget {
const Badge(this.text);
final String text;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
// These constants are sized to give 1 digit badges a circular look.
const badgeCornerRadius = 12.0;
const badgePadding = 6.0;
return Container(
decoration: BoxDecoration(
color: theme.primaryColor,
borderRadius: BorderRadius.circular(badgeCornerRadius),
),
padding: const EdgeInsets.symmetric(
vertical: borderPadding,
horizontal: badgePadding,
),
child: Text(
text,
// Use a slightly smaller font for the badge.
style: theme.primaryTextTheme.bodyText2.apply(fontSizeDelta: -1),
),
);
}
}
/// A widget, commonly used for icon buttons, that provides a tooltip with a
/// common delay before the tooltip is shown.
class DevToolsTooltip extends StatelessWidget {
const DevToolsTooltip({
Key key,
this.message,
this.richMessage,
@required this.child,
this.waitDuration = tooltipWait,
this.preferBelow = false,
this.padding = const EdgeInsets.all(defaultSpacing),
this.decoration,
this.textStyle,
}) : assert((message == null) != (richMessage == null)),
super(key: key);
final String message;
final InlineSpan richMessage;
final Widget child;
final Duration waitDuration;
final bool preferBelow;
final EdgeInsetsGeometry padding;
final Decoration decoration;
final TextStyle textStyle;
@override
Widget build(BuildContext context) {
TextStyle style = textStyle;
if (richMessage == null) {
style = TextStyle(
color: Theme.of(context).colorScheme.tooltipTextColor,
fontSize: defaultFontSize,
);
}
return Tooltip(
message: message,
richMessage: richMessage,
waitDuration: waitDuration,
preferBelow: preferBelow,
padding: padding,
textStyle: style,
decoration: decoration,
child: child,
);
}
}
class DevToolsIconButton extends StatelessWidget {
const DevToolsIconButton({
Key key,
this.iconData,
this.iconWidget,
@required this.onPressed,
@required this.tooltip,
@required this.gaScreen,
@required this.gaSelection,
}) : assert((iconData == null) != (iconWidget == null)),
super(key: key);
final IconData iconData;
final Widget iconWidget;
final VoidCallback onPressed;
final String tooltip;
final String gaScreen;
final String gaSelection;
@override
Widget build(BuildContext context) {
final icon = iconData != null
? Icon(
iconData,
size: defaultIconSize,
)
: iconWidget;
return DevToolsTooltip(
message: tooltip,
child: TextButton(
onPressed: () {
ga.select(gaScreen, gaSelection);
onPressed();
},
child: Container(
height: defaultButtonHeight,
width: defaultButtonHeight,
child: icon,
),
),
);
}
}
/// A wrapper around a TextButton, an Icon, and an optional Tooltip; used for
/// small toolbar actions.
class ToolbarAction extends StatelessWidget {
const ToolbarAction({
@required this.icon,
@required this.onPressed,
this.tooltip,
Key key,
}) : super(key: key);
final IconData icon;
final String tooltip;
final VoidCallback onPressed;
@override
Widget build(BuildContext context) {
final button = TextButton(
style: TextButton.styleFrom(
padding: EdgeInsets.zero,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
onPressed: onPressed,
child: Icon(icon, size: actionsIconSize),
);
return tooltip == null
? button
: DevToolsTooltip(
message: tooltip,
child: button,
);
}
}
/// Create a bordered, fixed-height header area with a title and optional child
/// on the right-hand side.
///
/// This is typically used as a title for a logical area of the screen.
class AreaPaneHeader extends StatelessWidget implements PreferredSizeWidget {
const AreaPaneHeader({
Key key,
@required this.title,
this.maxLines = 1,
this.needsTopBorder = true,
this.needsBottomBorder = true,
this.needsLeftBorder = false,
this.leftActions = const [],
this.scrollableCenterActions = const [],
this.rightActions = const [],
this.leftPadding = defaultSpacing,
this.rightPadding = densePadding,
this.tall = false,
}) : super(key: key);
final Widget title;
final int maxLines;
final bool needsTopBorder;
final bool needsBottomBorder;
final bool needsLeftBorder;
final List<Widget> leftActions;
final List<Widget> rightActions;
final List<Widget> scrollableCenterActions;
final double leftPadding;
final double rightPadding;
final bool tall;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return SizedBox.fromSize(
size: preferredSize,
child: Container(
decoration: BoxDecoration(
border: Border(
top: needsTopBorder ? defaultBorderSide(theme) : BorderSide.none,
bottom:
needsBottomBorder ? defaultBorderSide(theme) : BorderSide.none,
left: needsLeftBorder ? defaultBorderSide(theme) : BorderSide.none,
),
color: theme.titleSolidBackgroundColor,
),
padding: EdgeInsets.only(left: leftPadding, right: rightPadding),
alignment: Alignment.centerLeft,
child: Row(
children: [
DefaultTextStyle(
maxLines: maxLines,
overflow: TextOverflow.ellipsis,
style: theme.textTheme.subtitle2,
child: title,
),
..._buildActions(),
],
),
),
);
}
List<Widget> _buildActions() {
return [
if (scrollableCenterActions.isEmpty)
Expanded(
child: Row(
children: leftActions,
),
),
if (scrollableCenterActions.isNotEmpty) ...[
...leftActions,
Expanded(
// TODO(kenz): make this look more scrollable when there are too many
// actions. Either with a faded overlay over the end of the list or
// with a scrollbar.
child: ListView(
scrollDirection: Axis.horizontal,
children: scrollableCenterActions,
),
)
],
...rightActions,
];
}
@override
Size get preferredSize {
return Size.fromHeight(
tall ? areaPaneHeaderHeight + 2 * densePadding : areaPaneHeaderHeight,
);
}
}
BorderSide defaultBorderSide(ThemeData theme) {
return BorderSide(color: theme.focusColor);
}
class DevToolsToggleButtonGroup extends StatelessWidget {
const DevToolsToggleButtonGroup({
Key key,
@required this.children,
@required this.selectedStates,
@required this.onPressed,
}) : super(key: key);
final List<Widget> children;
final List<bool> selectedStates;
final void Function(int) onPressed;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return ToggleButtons(
borderRadius:
const BorderRadius.all(Radius.circular(defaultBorderRadius)),
color: theme.colorScheme.toggleButtonsTitle,
selectedColor: theme.colorScheme.toggleButtonsTitleSelected,
fillColor: theme.colorScheme.toggleButtonsFillSelected,
textStyle: theme.textTheme.bodyText1,
constraints: BoxConstraints(
minWidth: defaultButtonHeight,
minHeight: defaultButtonHeight,
),
children: children,
isSelected: selectedStates,
onPressed: onPressed,
);
}
}
/// Button to export data.
///
/// * `minScreenWidthForTextBeforeScaling`: The minimum width the button can be before the text is
/// omitted.
/// * `onPressed`: The callback to be called upon pressing the button.
class ExportButton extends IconLabelButton {
const ExportButton({
Key key,
@required VoidCallback onPressed,
@required double minScreenWidthForTextBeforeScaling,
String tooltip = 'Export data',
}) : super(
key: key,
onPressed: onPressed,
icon: Icons.file_download,
label: 'Export',
tooltip: tooltip,
minScreenWidthForTextBeforeScaling:
minScreenWidthForTextBeforeScaling,
);
}
class FilterButton extends StatelessWidget {
const FilterButton({
Key key,
@required this.onPressed,
@required this.isFilterActive,
}) : super(key: key);
final VoidCallback onPressed;
final bool isFilterActive;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return DevToolsTooltip(
message: 'Filter',
// TODO(kenz): this SizedBox wrapper should be unnecessary once
// https://github.com/flutter/flutter/issues/79894 is fixed.
child: SizedBox(
height: defaultButtonHeight,
child: OutlinedButton(
key: key,
onPressed: onPressed,
style: TextButton.styleFrom(
backgroundColor: isFilterActive
? theme.colorScheme.toggleButtonBackgroundColor
: Colors.transparent,
),
child: Icon(
Icons.filter_list,
size: defaultIconSize,
color: isFilterActive
? theme.colorScheme.toggleButtonForegroundColor
: theme.colorScheme.contrastForeground,
),
),
),
);
}
}
class RoundedDropDownButton<T> extends StatelessWidget {
const RoundedDropDownButton({
Key key,
this.value,
this.onChanged,
this.isDense = false,
this.style,
this.selectedItemBuilder,
this.items,
}) : super(key: key);
final T value;
final ValueChanged<T> onChanged;
final bool isDense;
final TextStyle style;
final DropdownButtonBuilder selectedItemBuilder;
final List<DropdownMenuItem<T>> items;
@override
Widget build(BuildContext context) {
return RoundedOutlinedBorder(
child: Center(
child: Container(
padding: const EdgeInsets.only(
left: defaultSpacing,
right: borderPadding,
),
height: defaultButtonHeight - 2.0, // subtract 2.0 for width of border
child: DropdownButtonHideUnderline(
child: DropdownButton<T>(
value: value,
onChanged: onChanged,
isDense: isDense,
style: style,
selectedItemBuilder: selectedItemBuilder,
items: items,
),
),