openSubPage function

void openSubPage(
  1. Widget page, {
  2. BuildContext? context,
  3. bool canPop = true,
  4. void onPopInvokedWithResult(
    1. bool,
    2. dynamic
    )?,
  5. void onPageClosed(
    1. dynamic result
    )?,
})

Implementation

void openSubPage(Widget page,
    {
      BuildContext? context,
      bool canPop = true,
      void Function(bool, dynamic)? onPopInvokedWithResult,
      void Function(dynamic result)? onPageClosed,
    })
{
  if (context == null && (!state.isContextLoaded || !state.appContext.mounted)) {
    assert(false,
    "App Context was not loaded or not mounted");

    return;
  }
  if (context != null && !context.mounted) {
    assert(false,
    "Provided Context was not loaded or not mounted");

    return;
  }
  context = context?? state.appContext;

  Navigator.push(
    context,
    MaterialPageRoute(
        builder: (context) => PopScope(
            canPop: canPop,
            onPopInvokedWithResult: (bool didPop, dynamic result) {
              if (onPopInvokedWithResult != null) {
                onPopInvokedWithResult(didPop, result);
              }

              if (didPop && onPageClosed != null) {
                onPageClosed(result);
              }
            },
            child: page,
        )
    ),
  );
}