buildWithChild method

  1. @override
Widget buildWithChild(
  1. BuildContext context,
  2. Widget? child
)
override

A build method that receives an extra child parameter.

This method may be called with a child different from the parameter passed to the constructor of SingleChildStatelessWidget. It may also be called again with a different child, without this widget being recreated.

Implementation

@override
Widget buildWithChild(BuildContext context, Widget? child) {
  return PopScope<T>(
    canPop: canPop,
    onPopInvokedWithResult: (didPop, result) async {
      onPopInvokedWithResult?.call(didPop, result);
      if (didPop) {
        return;
      }
      final navigator = Navigator.of(context);
      final shouldPop = await onShouldPop(result);
      if (shouldPop) {
        if (navigator.canPop()) {
          navigator.pop(result);
        } else {
          await SystemNavigator.pop();
        }
      }
    },
    child: child!,
  );
}