Skip to content

Conversation

@justinmc
Copy link
Contributor

@justinmc justinmc commented Aug 9, 2023

Root predictive back (#120385) was reverted in #132167. This PR is an attempt to reland it.

The reversion happened due to failed Google tests (b/295073110).

@justinmc justinmc self-assigned this Aug 9, 2023
@github-actions github-actions bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. f: cupertino flutter/packages/flutter/cupertino repository d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos f: routes Navigator, Router, and related APIs. labels Aug 9, 2023
/// [Android's predictive back](https://developer.android.com/guide/navigation/predictive-back-gesture)
/// feature will not animate when this boolean is false.
/// {@endtemplate}
final bool canPop;
Copy link
Contributor

Choose a reason for hiding this comment

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

With the old WillPopScope, the API was expecting a Future, which enabled hooking this into showing a dialog before popping the route. How would we support that here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forgot to respond here because we discussed this on Discord, but for the record, I've added an example to the migration guide about this: flutter/website#9244. It's similar to the pop_scope.0.dart example in this PR.

Copy link

@quyenvsp quyenvsp Nov 16, 2023

Choose a reason for hiding this comment

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

@justinmc it work in case pop to previous route. But can you please example how to hide the app when double-back at first route?

Before

  Future<bool> onWillPop() {
    DateTime now = DateTime.now();
    if (_currentBackPressTime == null ||
        now.difference(_currentBackPressTime!) > const Duration(seconds: 2)) {
      _currentBackPressTime = now;
      DialogUtil.showSnackBar(context, content: 'Press back again to exit');
      return Future.value(false);
    }
    return Future.value(true);
  }

I can not do it with new PopScope, the only way required setState to change canPop

Update: Fixed by using SystemNavigator.pop();

@justinmc justinmc force-pushed the revert-132167-new_revert branch from 66374fb to d7a302a Compare August 16, 2023 17:50
onNotification: widget.onNavigationNotification == null ? null : (NavigationNotification notification) {
// By default, don't do anything with navigation notifications if
// there is no engine attached.
if (widget.onNavigationNotification == WidgetsApp.defaultOnNavigationNotification
Copy link
Contributor

Choose a reason for hiding this comment

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

This is weird can we work around this by making this non static? or a static method that takes in a widget state or changenotifier and returns a function ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It turns out I do need this fix. I've cleaned it up and made it non-static in this commit: b332896

@justinmc justinmc force-pushed the revert-132167-new_revert branch from 39c9b56 to 56c8777 Compare August 17, 2023 16:22
@justinmc justinmc requested a review from chunhtai August 17, 2023 22:14
Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

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

LGTM

@justinmc justinmc added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 17, 2023
@auto-submit auto-submit bot merged commit f68d03f into master Aug 17, 2023
@auto-submit auto-submit bot deleted the revert-132167-new_revert branch August 17, 2023 23:55
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 18, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 18, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 18, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 18, 2023
parlough added a commit to flutter/website that referenced this pull request Aug 21, 2023
A user requested this example be added to the migration guide [on
Discord](https://discord.com/channels/608014603317936148/969301283825659914/1140422179511603290).
I think it's a reasonable request.

Follow up on: #8952
Framework PR: flutter/flutter#132249

---------

Co-authored-by: Parker Lougheed <[email protected]>
// Avoid dispatching a notification in the middle of a build.
switch (SchedulerBinding.instance.schedulerPhase) {
case SchedulerPhase.postFrameCallbacks:
notification.dispatch(subtreeContext);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it intentional that there's no break here? If so, can you add a comment that you're intentionally falling through?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems 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: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. f: routes Navigator, Router, and related APIs. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants