Reputation: 1005
I'm not asking about webview. This is about Flutter web app. I need to go back to a specific page when user press back button which is inbuilt in browser.
Any guessing ?
I'm getting this error when I press back button
Error: Assertion failed: org-dartlang-
sdk:///flutter_web_sdk/lib/_engine/engine/history.dart:110:14
_userProvidedRouteName != null
is not true
at Object.throw_ [as throw] (http://localhost:8300/dart_sdk.js:4770:11)
at Object.assertFailed (http://localhost:8300/dart_sdk.js:4721:15)
Upvotes: 24
Views: 26219
Reputation: 745
If you are looking to emulate the browser back button from within a pushed route in your Flutter web app, I have achieved this via use of Router.neglect:
AppBar(
leading: GestureDetector(
child: const Icon(Icons.close_rounded, color: Colors.white),
onTap: () => Router.neglect(context, () => context.pop()),
),
),
Upvotes: 0
Reputation: 901
For disable this chrome back button you can use
onWillPop: () {
exit(0);
return new Future(() => true);
}
and for hand back press for back page you can use willPop:
WillPopScope(
onWillPop: () async => Navigator.push(context, MaterialPageRoute(builder: (context) => YOUROLDPAGE()),
child: Scaffold(
appBar: new AppBar(
title: new Text("Home Page"),
),
),
);
Upvotes: -3
Reputation: 3076
onWillPop: () {
Navigator.pop(context);
return new Future(() => true);
}
Upvotes: 4
Reputation: 740
In case if you don't want to navigate to a new page
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async => true,
child: Scaffold(
key: _scaffold,
backgroundColor: Colors.indigo,
body: Center(
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
registerForm(),
registerBtn(),
SizedBox(height: 30,),
_buildSignInButton()
],
),
),
),
),
);
}
Upvotes: 14
Reputation: 1266
onWillPop
Navigate to a new Page
class webScope extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new WillPopScope(
onWillPop: () async => Navigator.push(context, MaterialPageRoute(builder: (context) => new NewPageWidget())),
child: Scaffold(
appBar: new AppBar(
title: new Text("webScope"),
),
),
);
}
}
Upvotes: 3