I am using the below code to navigate to a widget which shows the webview
context.goNamed(
Routes.webRoute.name,
pathParameters: {
Params.webUrl.key: state.WebUrl,
Params.Source.key: Source.Options.name,
},
);
as I am using goRouter, so the goNamed will remove all the backstacks and shows the webview in fullscreen.
But the problem is when I backpress it closes the app as it doesn't have any backstack.
Obviously I can use pushNamed instead of goNamed and the backpress works fine. But I have a bottom navigation in the screen which does not hide in this case.
Does anybody know any workaround in this situation so that my bottom navigation also should be hidden and the backpress should work also?
The webview widget code is provided below:
Scaffold(
appBar: AppBar(
backgroundColor: AppColors.white,
title: StyledText.subtitle(
AppLocalizations.of(context)!.webview,
),
centerTitle: true,
leading: IconButton(
onPressed: (() async {
if (await webViewController!.canGoBack()) {
webViewController!.goBack();
} else {
if (context.mounted) {
context.pop();
}
}
}),
icon: const Icon(Icons.arrow_back),
),
),
body: Center(
child: Column(children: <Widget>[
Expanded(
child: InAppWebView(
key: webViewKey,
onLoadStart: (controller, url) {},
onLoadStop: (controller, url) {
if (currentUrl == ApiConstants.success) {
BlocProvider.of<PaymentBloc>(context).add(
SuccessfulEvent(),
);
} else if (currentUrl == ApiConstants.failure) {
BlocProvider.of<PaymentBloc>(context).add(
FailureEvent(),
);
} else {
webViewController!.loadUrl(
urlRequest: URLRequest(url: url),
);
}
},
initialUrlRequest: URLRequest(
url: Uri.parse(
state.Url,
),
),
onWebViewCreated: (controller) {
webViewController = controller;
},
),
),
]),
),
),