maybePop method

Future<void> maybePop(
  1. BuildContext context
)

Pops the topmost Flutter route if the navigator can pop, otherwise closes the native container (Activity/ViewController).

Use this as the handler for custom back buttons in add-to-app screens:

IconButton(
  icon: const Icon(Icons.arrow_back),
  onPressed: () => InlayNavigator.instance.maybePop(context),
)

Implementation

Future<void> maybePop(BuildContext context) async {
  final navigator = Navigator.of(context);
  if (navigator.canPop()) {
    navigator.pop();
  } else {
    await pop();
  }
}