如何在浏览器中为 Flutter Web App 配置返回按钮
How to configure go back button in Browser for Flutter Web App
我问的不是网络视图。这是关于 Flutter 网络应用程序的。当用户按下浏览器内置的后退按钮时,我需要返回到特定页面。
猜对了吗?
当我按下后退按钮时出现此错误
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)
onWillPop
导航到新页面
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"),
),
),
);
}
}
如果您不想导航到新页面
@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()
],
),
),
),
),
);
}
onWillPop: () {
Navigator.pop(context);
return new Future(() => true);
}
onWillPop: () {
exit(0);
return new Future(() => true);
}
我问的不是网络视图。这是关于 Flutter 网络应用程序的。当用户按下浏览器内置的后退按钮时,我需要返回到特定页面。
猜对了吗?
当我按下后退按钮时出现此错误
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)
onWillPop
导航到新页面
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"),
),
),
);
}
}
如果您不想导航到新页面
@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()
],
),
),
),
),
);
}
onWillPop: () {
Navigator.pop(context);
return new Future(() => true);
}
onWillPop: () {
exit(0);
return new Future(() => true);
}