@@ -15,6 +15,7 @@ import 'package:flutter/widgets.dart';
15
15
16
16
import 'button.dart' ;
17
17
import 'colors.dart' ;
18
+ import 'constants.dart' ;
18
19
import 'icons.dart' ;
19
20
import 'interface_level.dart' ;
20
21
import 'localizations.dart' ;
@@ -534,46 +535,44 @@ class _CupertinoAppState extends State<CupertinoApp> {
534
535
Widget _exitWidgetSelectionButtonBuilder (
535
536
BuildContext context, {
536
537
required VoidCallback onPressed,
538
+ required String semanticLabel,
537
539
required GlobalKey key,
538
540
}) {
539
- return CupertinoButton (
540
- key: key,
541
- color: _widgetSelectionButtonsBackgroundColor (context),
542
- padding: EdgeInsets .zero,
541
+ return _CupertinoInspectorButton .filled (
543
542
onPressed: onPressed,
544
- child: Icon (
545
- CupertinoIcons .xmark,
546
- size: 28.0 ,
547
- color: _widgetSelectionButtonsForegroundColor (context),
548
- semanticLabel: 'Exit Select Widget mode.' ,
549
- ),
543
+ semanticLabel: semanticLabel,
544
+ icon: CupertinoIcons .xmark,
545
+ buttonKey: key,
550
546
);
551
547
}
552
548
553
549
Widget _moveExitWidgetSelectionButtonBuilder (
554
550
BuildContext context, {
555
551
required VoidCallback onPressed,
552
+ required String semanticLabel,
556
553
bool isLeftAligned = true ,
557
554
}) {
558
- return CupertinoButton (
555
+ return _CupertinoInspectorButton . iconOnly (
559
556
onPressed: onPressed,
560
- padding: EdgeInsets .zero,
561
- child: Icon (
562
- isLeftAligned ? CupertinoIcons .arrow_right : CupertinoIcons .arrow_left,
563
- size: 32.0 ,
564
- color: _widgetSelectionButtonsBackgroundColor (context),
565
- semanticLabel:
566
- 'Move "Exit Select Widget mode" button to the ${isLeftAligned ? 'right' : 'left' }.' ,
567
- ),
557
+ semanticLabel: semanticLabel,
558
+ icon: isLeftAligned ? CupertinoIcons .arrow_right : CupertinoIcons .arrow_left,
568
559
);
569
560
}
570
561
571
- Color _widgetSelectionButtonsForegroundColor (BuildContext context) {
572
- return CupertinoTheme .of (context).primaryContrastingColor;
573
- }
574
-
575
- Color _widgetSelectionButtonsBackgroundColor (BuildContext context) {
576
- return CupertinoTheme .of (context).primaryColor;
562
+ Widget _tapBehaviorButtonBuilder (
563
+ BuildContext context, {
564
+ required VoidCallback onPressed,
565
+ required String semanticLabel,
566
+ required bool selectionOnTapEnabled,
567
+ }) {
568
+ return _CupertinoInspectorButton .toggle (
569
+ onPressed: onPressed,
570
+ semanticLabel: semanticLabel,
571
+ // This icon is also used for the Material-styled button and for DevTools.
572
+ // It should be updated in all 3 places if changed.
573
+ icon: CupertinoIcons .cursor_rays,
574
+ toggledOn: selectionOnTapEnabled,
575
+ );
577
576
}
578
577
579
578
WidgetsApp _buildWidgetApp (BuildContext context) {
@@ -607,6 +606,7 @@ class _CupertinoAppState extends State<CupertinoApp> {
607
606
debugShowCheckedModeBanner: widget.debugShowCheckedModeBanner,
608
607
exitWidgetSelectionButtonBuilder: _exitWidgetSelectionButtonBuilder,
609
608
moveExitWidgetSelectionButtonBuilder: _moveExitWidgetSelectionButtonBuilder,
609
+ tapBehaviorButtonBuilder: _tapBehaviorButtonBuilder,
610
610
shortcuts: widget.shortcuts,
611
611
actions: widget.actions,
612
612
restorationScopeId: widget.restorationScopeId,
@@ -642,6 +642,7 @@ class _CupertinoAppState extends State<CupertinoApp> {
642
642
debugShowCheckedModeBanner: widget.debugShowCheckedModeBanner,
643
643
exitWidgetSelectionButtonBuilder: _exitWidgetSelectionButtonBuilder,
644
644
moveExitWidgetSelectionButtonBuilder: _moveExitWidgetSelectionButtonBuilder,
645
+ tapBehaviorButtonBuilder: _tapBehaviorButtonBuilder,
645
646
shortcuts: widget.shortcuts,
646
647
actions: widget.actions,
647
648
restorationScopeId: widget.restorationScopeId,
@@ -680,3 +681,83 @@ class _CupertinoAppState extends State<CupertinoApp> {
680
681
);
681
682
}
682
683
}
684
+
685
+ class _CupertinoInspectorButton extends InspectorButton {
686
+ const _CupertinoInspectorButton .filled ({
687
+ required super .onPressed,
688
+ required super .semanticLabel,
689
+ required super .icon,
690
+ super .buttonKey,
691
+ }) : super .filled ();
692
+
693
+ const _CupertinoInspectorButton .toggle ({
694
+ required super .onPressed,
695
+ required super .semanticLabel,
696
+ required super .icon,
697
+ super .toggledOn,
698
+ }) : super .tog
F41A
gle ();
699
+
700
+ const _CupertinoInspectorButton .iconOnly ({
701
+ required super .onPressed,
702
+ required super .semanticLabel,
703
+ required super .icon,
704
+ }) : super .iconOnly ();
705
+
706
+ @override
707
+ Widget build (BuildContext context) {
708
+ final Icon buttonIcon = Icon (
709
+ icon,
710
+ semanticLabel: semanticLabel,
711
+ size: iconSizeForVariant,
712
+ color: foregroundColor (context),
713
+ );
714
+
715
+ return Padding (
716
+ key: buttonKey,
717
+ padding: const EdgeInsets .all (
718
+ (kMinInteractiveDimensionCupertino - InspectorButton .buttonSize) / 2 ,
719
+ ),
720
+ child:
721
+ variant == InspectorButtonVariant .toggle && ! toggledOn!
722
+ ? CupertinoButton .tinted (
723
+ minSize: InspectorButton .buttonSize,
724
+ onPressed: onPressed,
725
+ padding: EdgeInsets .zero,
726
+ child: buttonIcon,
727
+ )
728
+ : CupertinoButton (
729
+ minSize: InspectorButton .buttonSize,
730
+ onPressed: onPressed,
731
+ padding: EdgeInsets .zero,
732
+ color: backgroundColor (context),
733
+ child: buttonIcon,
734
+ ),
735
+ );
736
+ }
737
+
738
+ @override
739
+ Color foregroundColor (BuildContext context) {
740
+ final Color primaryColor = CupertinoTheme .of (context).primaryColor;
741
+ final Color secondaryColor = CupertinoTheme .of (context).primaryContrastingColor;
742
+ switch (variant) {
743
+ case InspectorButtonVariant .filled:
744
+ return secondaryColor;
745
+ case InspectorButtonVariant .iconOnly:
746
+ return primaryColor;
747
+ case InspectorButtonVariant .toggle:
748
+ return ! toggledOn! ? primaryColor : secondaryColor;
749
+ }
750
+ }
751
+
752
+ @override
753
+ Color backgroundColor (BuildContext context) {
754
+ final Color primaryColor = CupertinoTheme .of (context).primaryColor;
755
+ switch (variant) {
756
+ case InspectorButtonVariant .filled:
757
+ case InspectorButtonVariant .toggle:
758
+ return primaryColor;
759
+ case InspectorButtonVariant .iconOnly:
760
+ return const Color (0x00000000 );
761
+ }
762
+ }
763
+ }
0 commit comments