openSubPage function
void
openSubPage(
- Widget page, {
- BuildContext? context,
- bool canPop = true,
- void onPopInvokedWithResult(
- bool,
- dynamic
- void onPageClosed(
- 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,
)
),
);
}