Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[beta] CP request for https://github.com/flutter/flutter/pull/167677 #168386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 106 additions & 25 deletions packages/flutter/lib/src/cupertino/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:flutter/widgets.dart';

import 'button.dart';
import 'colors.dart';
import 'constants.dart';
import 'icons.dart';
import 'interface_level.dart';
import 'localizations.dart';
Expand Down Expand Up @@ -534,46 +535,44 @@ class _CupertinoAppState extends State<CupertinoApp> {
Widget _exitWidgetSelectionButtonBuilder(
BuildContext context, {
required VoidCallback onPressed,
required String semanticLabel,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI for future changes, we're desperately trying to align on semantic*s*Label across the framework. This is private so we can fix it pretty easily with the work we're already doing on this later.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good to know, thanks!

required GlobalKey key,
}) {
return CupertinoButton(
key: key,
color: _widgetSelectionButtonsBackgroundColor(context),
padding: EdgeInsets.zero,
return _CupertinoInspectorButton.filled(
onPressed: onPressed,
child: Icon(
CupertinoIcons.xmark,
size: 28.0,
color: _widgetSelectionButtonsForegroundColor(context),
semanticLabel: 'Exit Select Widget mode.',
),
semanticLabel: semanticLabel,
icon: CupertinoIcons.xmark,
buttonKey: key,
);
}

Widget _moveExitWidgetSelectionButtonBuilder(
BuildContext context, {
required VoidCallback onPressed,
required String semanticLabel,
bool isLeftAligned = true,
}) {
return CupertinoButton(
return _CupertinoInspectorButton.iconOnly(
onPressed: onPressed,
padding: EdgeInsets.zero,
child: Icon(
isLeftAligned ? CupertinoIcons.arrow_right : CupertinoIcons.arrow_left,
size: 32.0,
color: _widgetSelectionButtonsBackgroundColor(context),
semanticLabel:
'Move "Exit Select Widget mode" button to the ${isLeftAligned ? 'right' : 'left'}.',
),
semanticLabel: semanticLabel,
icon: isLeftAligned ? CupertinoIcons.arrow_right : CupertinoIcons.arrow_left,
);
}

Color _widgetSelectionButtonsForegroundColor(BuildContext context) {
return CupertinoTheme.of(context).primaryContrastingColor;
}

Color _widgetSelectionButtonsBackgroundColor(BuildContext context) {
return CupertinoTheme.of(context).primaryColor;
Widget _tapBehaviorButtonBuilder(
BuildContext context, {
required VoidCallback onPressed,
required String semanticLabel,
required bool selectionOnTapEnabled,
}) {
return _CupertinoInspectorButton.toggle(
onPressed: onPressed,
semanticLabel: semanticLabel,
// This icon is also used for the Material-styled button and for DevTools.
// It should be updated in all 3 places if changed.
icon: CupertinoIcons.cursor_rays,
toggledOn: selectionOnTapEnabled,
);
}

WidgetsApp _buildWidgetApp(BuildContext context) {
Expand Down Expand Up @@ -607,6 +606,7 @@ class _CupertinoAppState extends State<CupertinoApp> {
debugShowCheckedModeBanner: widget.debugShowCheckedModeBanner,
exitWidgetSelectionButtonBuilder: _exitWidgetSelectionButtonBuilder,
moveExitWidgetSelectionButtonBuilder: _moveExitWidgetSelectionButtonBuilder,
tapBehaviorButtonBuilder: _tapBehaviorButtonBuilder,
shortcuts: widget.shortcuts,
actions: widget.actions,
restorationScopeId: widget.restorationScopeId,
Expand Down Expand Up @@ -642,6 +642,7 @@ class _CupertinoAppState extends State<CupertinoApp> {
debugShowCheckedModeBanner: widget.debugShowCheckedModeBanner,
exitWidgetSelectionButtonBuilder: _exitWidgetSelectionButtonBuilder,
moveExitWidgetSelectionButtonBuilder: _moveExitWidgetSelectionButtonBuilder,
tapBehaviorButtonBuilder: _tapBehaviorButtonBuilder,
shortcuts: widget.shortcuts,
actions: widget.actions,
restorationScopeId: widget.restorationScopeId,
Expand Down Expand Up @@ -680,3 +681,83 @@ class _CupertinoAppState extends State<CupertinoApp> {
);
}
}

class _CupertinoInspectorButton extends InspectorButton {
const _CupertinoInspectorButton.filled({
required super.onPressed,
required super.semanticLabel,
required super.icon,
super.buttonKey,
}) : super.filled();

const _CupertinoInspectorButton.toggle({
required super.onPressed,
required super.semanticLabel,
required super.icon,
super.toggledOn,
}) : super.toggle();

const _CupertinoInspectorButton.iconOnly({
required super.onPressed,
required super.semanticLabel,
required super.icon,
}) : super.iconOnly();

@override
Widget build(BuildContext context) {
final Icon buttonIcon = Icon(
icon,
semanticLabel: semanticLabel,
size: iconSizeForVariant,
color: foregroundColor(context),
);

return Padding(
key: buttonKey,
padding: const EdgeInsets.all(
(kMinInteractiveDimensionCupertino - InspectorButton.buttonSize) / 2,
),
child:
variant == InspectorButtonVariant.toggle && !toggledOn!
? CupertinoButton.tinted(
minSize: InspectorButton.buttonSize,
onPressed: onPressed,
padding: EdgeInsets.zero,
child: buttonIcon,
)
: CupertinoButton(
minSize: InspectorButton.buttonSize,
onPressed: onPressed,
padding: EdgeInsets.zero,
color: backgroundColor(context),
child: buttonIcon,
),
);
}

@override
Color foregroundColor(BuildContext context) {
final Color primaryColor = CupertinoTheme.of(context).primaryColor;
final Color secondaryColor = CupertinoTheme.of(context).primaryContrastingColor;
switch (variant) {
case InspectorButtonVariant.filled:
return secondaryColor;
case InspectorButtonVariant.iconOnly:
return primaryColor;
case InspectorButtonVariant.toggle:
return !toggledOn! ? primaryColor : secondaryColor;
}
}

@override
Color backgroundColor(BuildContext context) {
final Color primaryColor = CupertinoTheme.of(context).primaryColor;
switch (variant) {
case InspectorButtonVariant.filled:
case InspectorButtonVariant.toggle:
return primaryColor;
case InspectorButtonVariant.iconOnly:
return const Color(0x00000000);
}
}
}
Loading