Add GoRouter maybePop

This issue has been tracked since 2022-11-25.

Use case

Navigator have maybePop. I think it would be better if GoRouter also have maybePop or something similar. Atm it only has canPop and pop, and you have to use both to achieve something similar to maybePop.

final goRouter = GoRouter.of(context);
if (goRouter.canPop()) {
  goRouter.pop();
}

Proposal

Add maybePop

GoRouter.of(context).maybePop();
maRci002 wrote this answer on 2022-11-25

Atm it only has canPop and pop, and you have to use both to achieve something similar to maybePop.

maybePop isn't shorthand for if (canPop()) {pop()}

maybePop returns a Future<bool> since it consults with current route's Route.willPop which means if you have a WillPopScope in your widget tree it might veto the pop.

However WillPopScope shouldn't be used with Router:

Note: You can’t prevent navigation from page-backed screens using WillPopScope. Instead, you should consult your routing package’s API documentation.

See #102408 for details.

More Details About Repo
Owner Name flutter
Repo Name flutter
Full Name flutter/flutter
Language Dart
Created Date 2015-03-06
Updated Date 2022-12-07
Star Count 147031
Watcher Count 3560
Fork Count 23915
Issue Count 11300

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date