[go: nahoru, domu]

Skip to content
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

Adaptive alert dialog #124336

Merged
merged 11 commits into from
Apr 18, 2023
Merged

Conversation

MitchellGoodwin
Copy link
Contributor
@MitchellGoodwin MitchellGoodwin commented Apr 6, 2023

Fixes #102811. Adds an adaptive constructor to AlertDialog, along with the adaptive function showAdaptiveDialog.

Screenshot 2023-04-06 at 10 40 18 AM

Screenshot 2023-04-06 at 10 42 50 AM

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos documentation f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. team Infra upgrades, team productivity, code health, technical debt. See also team: labels. labels Apr 6, 2023
@MitchellGoodwin MitchellGoodwin marked this pull request as ready for review April 6, 2023 19:32
///
/// On Cupertino platforms, [barrierColor], [useSafeArea], and
/// [traversalEdgeBehavior] are ignored.
Future<T?> showAdaptiveDialog<T>({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we have a pattern of adaptive functions? I wasn't sure the right way to name this.

Copy link
Contributor

Choose a reason for hiding this comment

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

This name sounds good to me. I don't think we have any patterns for the name of the adaptive function. But I'm not very sure. Maybe we can collect some suggestions from @HansMuller ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@HansMuller if you could take a quick peek at this.

Copy link
Contributor
@QuncCccccc QuncCccccc left a comment

Choose a reason for hiding this comment

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

LGTM:) !

Widget build(BuildContext context) {
return MaterialApp(
// Try this: set the platform to platform.android and see the difference
theme: ThemeData(platform: TargetPlatform.iOS),
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe here we can also set useMaterial3 to true to see the latest style of Material alert dialog:)
Screenshot 2023-04-06 at 2 55 02 PM

///
/// On Cupertino platforms, [barrierColor], [useSafeArea], and
/// [traversalEdgeBehavior] are ignored.
Future<T?> showAdaptiveDialog<T>({
Copy link
Contributor

Choose a reason for hiding this comment

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

This name sounds good to me. I don't think we have any patterns for the name of the adaptive function. But I'm not very sure. Maybe we can collect some suggestions from @HansMuller ;)

),
actions: <Widget>[
TextButton(
onPressed: () {},
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe two space indent.

@MitchellGoodwin MitchellGoodwin force-pushed the adaptive-alert-dialog branch 2 times, most recently from a41e9fe to 52ae952 Compare April 7, 2023 17:27
@@ -24,6 +24,8 @@ import 'theme_data.dart';

const EdgeInsets _defaultInsetPadding = EdgeInsets.symmetric(horizontal: 40.0, vertical: 24.0);

enum _DialogType {material, adaptive }
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
enum _DialogType {material, adaptive }
enum _DialogType { material, adaptive }

packages/flutter/test/material/dialog_test.dart Outdated Show resolved Hide resolved
packages/flutter/test/material/dialog_test.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/material/dialog.dart Outdated Show resolved Hide resolved
Comment on lines 415 to 417
/// are ignored: [title], [content], [actions], [scrollController],
/// [actionScrollController], [insetAnimationDuration], and
/// [insetAnimationCurve]. If a [AlertDialog] is created, [scrollController],
Copy link
Member
@werainkhatri werainkhatri Apr 10, 2023

Choose a reason for hiding this comment

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

the newly added params are NOT ignored in case of CupertinoAlertDialog. they're only ignored in case of material AlertDialog.

/// Typically passed as a child of [showAdaptiveDialog], which will display
/// the alert differently based on platform.
///
/// If a [CupertinoAlertDialog] is created, all parameters are ignored except
Copy link
Member
@werainkhatri werainkhatri Apr 10, 2023

Choose a reason for hiding this comment

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

i'm sorry, but i feel stating it as a positive instead of a double negative would be easier to understand, something like ... only these parameters are used:. could you check other adaptive widgets / functions for similar documentation?

moving the statement for AlertDialog to a newline would help too.

lemme know your thoughts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, that makes sense. On the other adaptive widgets we so far have only called out which ones are ignored, instead of which ones aren't.

Copy link
Contributor
@QuncCccccc QuncCccccc left a comment

Choose a reason for hiding this comment

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

It looks good! Just left one comment for the newly added fields:) Thanks!

@@ -634,10 +703,73 @@ class AlertDialog extends StatelessWidget {
/// button bar.
final bool scrollable;

/// A scroll controller that can be used to control the scrolling of the
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Maybe we can add {@template ...}... {@endtemplate} for the cupertino AlertDialog's API documentation so that here we can directly use {@macro ...}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Question: would this be necessary if we go with the factory implementation you mentioned below? That would hide the Cupertino specific properties somewhat. I can add them with the documentation for the .adaptive but I'm thinking it's better to just let them go to the page for CupertinoAlertDialog at that point.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah that makes sense. SGTM!

///
/// * [actionScrollController], which can be used for controlling the actions
/// section when there are many actions.
final ScrollController? scrollController;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm considering if we should add these 4 APIs here because the material AlertDialog will not use them at all. Another way I can think of is to use factory keyword when we create AlertDialog.adaptive constructor, and the factory constructor will be assigned to a private subclass which has the extra APIs. An example can be FilledButton.icon(). By using factory, we can add new parameters only in the AlertDialog.adaptive constructor without adding new fields for AlertDialog. I think that would be something like: https://gist.github.com/QuncCccccc/93f22070b6b459912eeddb03ff55d1ec

But please let me know if this doesn't make sense:)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No that makes sense, and that looks a lot cleaner. Thank you!

Copy link
Member

Choose a reason for hiding this comment

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

that's way better.

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah just one more minor comment(Sorry!). I'm just thinking to follow Greg's this PR: #124080, probably it's better to rename the MyApp class to AdaptiveAlertDialogApp or something else:)

Copy link
Contributor
@QuncCccccc QuncCccccc left a comment

Choose a reason for hiding this comment

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

LGTM:)

Copy link
Member
@werainkhatri werainkhatri left a comment

Choose a reason for hiding this comment

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

LGTM :D

@MitchellGoodwin MitchellGoodwin added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 18, 2023
@auto-submit auto-submit bot merged commit bd2617e into flutter:master Apr 18, 2023
68 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 19, 2023
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Apr 19, 2023
flutter/flutter@42fb0b2...3476b96

2023-04-19 42216813+eliasyishak@users.noreply.github.com Update helper message for `--suppress-analytics` (flutter/flutter#124810)
2023-04-19 engine-flutter-autoroll@skia.org Roll Flutter Engine from 8b7cdb02f7f3 to 609f9d536494 (1 revision) (flutter/flutter#125097)
2023-04-19 engine-flutter-autoroll@skia.org Roll Flutter Engine from 099ed6c62d04 to 8b7cdb02f7f3 (6 revisions) (flutter/flutter#125094)
2023-04-19 engine-flutter-autoroll@skia.org Roll Flutter Engine from 5fcc7b719029 to 099ed6c62d04 (3 revisions) (flutter/flutter#125078)
2023-04-19 jmccandless@google.com Disableable ContextMenuButtonItems (flutter/flutter#124253)
2023-04-18 58190796+MitchellGoodwin@users.noreply.github.com Adaptive alert dialog (flutter/flutter#124336)
2023-04-18 engine-flutter-autoroll@skia.org Roll Flutter Engine from 6d263ea56a62 to 5fcc7b719029 (4 revisions) (flutter/flutter#125069)
2023-04-18 58529443+srujzs@users.noreply.github.com Remove package:js/dart:js_interop conflicts (flutter/flutter#124879)
2023-04-18 abadasamuelosp@gmail.com Remove double.fromEnvironment from dart-define doc (flutter/flutter#124102)
2023-04-18 40026920+KKimj@users.noreply.github.com Update to add Kim Jiun to `AUTHORS` (flutter/flutter#125026)
2023-04-18 gspencergoog@users.noreply.github.com Add controller argument to SubmenuButton (flutter/flutter#125000)
2023-04-18 engine-flutter-autoroll@skia.org Roll Flutter Engine from 879308a52228 to 6d263ea56a62 (1 revision) (flutter/flutter#125060)
2023-04-18 jmccandless@google.com Limit the number of Material spell check suggestions to 3 (flutter/flutter#124899)
2023-04-18 magder@google.com Remove impeller testowners (flutter/flutter#125056)
2023-04-18 110993981+htoor3@users.noreply.github.com [web] - Clean up skipped tests (flutter/flutter#124981)
2023-04-18 engine-flutter-autoroll@skia.org Roll Flutter Engine from 72b68622fffa to 879308a52228 (1 revision) (flutter/flutter#125057)
2023-04-18 goderbauer@google.com Remove unused getRootRenderObject and getSelectedRenderObject service extensions (flutter/flutter#124805)
2023-04-18 thkim1011@users.noreply.github.com l10n.yaml's nullable-getter option should default to true (flutter/flutter#124353)
2023-04-18 engine-flutter-autoroll@skia.org Roll Flutter Engine from 55bb065c607b to 72b68622fffa (1 revision) (flutter/flutter#125053)
2023-04-18 47866232+chunhtai@users.noreply.github.com Add vmservice for android build options (flutter/flutter#123034)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC rmistry@google.com,stuartmorgan@google.com,ychris@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
@reidbaker reidbaker mentioned this pull request Apr 21, 2023
8 tasks
nploi pushed a commit to nploi/packages that referenced this pull request Jul 16, 2023
…r#3760)

flutter/flutter@42fb0b2...3476b96

2023-04-19 42216813+eliasyishak@users.noreply.github.com Update helper message for `--suppress-analytics` (flutter/flutter#124810)
2023-04-19 engine-flutter-autoroll@skia.org Roll Flutter Engine from 8b7cdb02f7f3 to 609f9d536494 (1 revision) (flutter/flutter#125097)
2023-04-19 engine-flutter-autoroll@skia.org Roll Flutter Engine from 099ed6c62d04 to 8b7cdb02f7f3 (6 revisions) (flutter/flutter#125094)
2023-04-19 engine-flutter-autoroll@skia.org Roll Flutter Engine from 5fcc7b719029 to 099ed6c62d04 (3 revisions) (flutter/flutter#125078)
2023-04-19 jmccandless@google.com Disableable ContextMenuButtonItems (flutter/flutter#124253)
2023-04-18 58190796+MitchellGoodwin@users.noreply.github.com Adaptive alert dialog (flutter/flutter#124336)
2023-04-18 engine-flutter-autoroll@skia.org Roll Flutter Engine from 6d263ea56a62 to 5fcc7b719029 (4 revisions) (flutter/flutter#125069)
2023-04-18 58529443+srujzs@users.noreply.github.com Remove package:js/dart:js_interop conflicts (flutter/flutter#124879)
2023-04-18 abadasamuelosp@gmail.com Remove double.fromEnvironment from dart-define doc (flutter/flutter#124102)
2023-04-18 40026920+KKimj@users.noreply.github.com Update to add Kim Jiun to `AUTHORS` (flutter/flutter#125026)
2023-04-18 gspencergoog@users.noreply.github.com Add controller argument to SubmenuButton (flutter/flutter#125000)
2023-04-18 engine-flutter-autoroll@skia.org Roll Flutter Engine from 879308a52228 to 6d263ea56a62 (1 revision) (flutter/flutter#125060)
2023-04-18 jmccandless@google.com Limit the number of Material spell check suggestions to 3 (flutter/flutter#124899)
2023-04-18 magder@google.com Remove impeller testowners (flutter/flutter#125056)
2023-04-18 110993981+htoor3@users.noreply.github.com [web] - Clean up skipped tests (flutter/flutter#124981)
2023-04-18 engine-flutter-autoroll@skia.org Roll Flutter Engine from 72b68622fffa to 879308a52228 (1 revision) (flutter/flutter#125057)
2023-04-18 goderbauer@google.com Remove unused getRootRenderObject and getSelectedRenderObject service extensions (flutter/flutter#124805)
2023-04-18 thkim1011@users.noreply.github.com l10n.yaml's nullable-getter option should default to true (flutter/flutter#124353)
2023-04-18 engine-flutter-autoroll@skia.org Roll Flutter Engine from 55bb065c607b to 72b68622fffa (1 revision) (flutter/flutter#125053)
2023-04-18 47866232+chunhtai@users.noreply.github.com Add vmservice for android build options (flutter/flutter#123034)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC rmistry@google.com,stuartmorgan@google.com,ychris@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. team Infra upgrades, team productivity, code health, technical debt. See also team: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add .adaptive constructor for Dialogs
3 participants