将表单提交给 firebase 后无法禁用后退按钮
Unable to disable back button once a form is submitted to firebase
一旦我填写了表单并将其提交给 Firebase,代码就会将我导航到我的主页,但是当我按下 android phone 的后退按钮时,它会将用户发送到之前的表单包含所有先前填充数据的页面可用。我已经厌倦了使用 WillPopScope 函数来禁用我的 android phone 的后退按钮但没有响应..
我还使用 willpopscope 创建了一个函数并在 main 中调用它但没有结果。
@override
Widget build(BuildContext context) {
return new WillPopScope(
onWillPop: () async =>false,
child: new Scaffold(
appBar: new AppBar(
title: new Text('Welcome'),
actions: <Widget>[
_onbackpressed(), //tried disabling the back button by calling this fucntion
new FlatButton(
child: new Text('Logout',
style: new TextStyle(fontSize: 17.0, color: Colors.white)),
onPressed: _signOut)
],
),
body: _showTodoList(),
floatingActionButton: FloatingActionButton(
onPressed: () {
signupPage(context);
},
tooltip: 'Increment',
child: Icon(Icons.add),
)
),
);
}
//extra funtion to disable the back button-
_onbackpressed(){
return new WillPopScope(
onWillPop: () async =>false,
child: new Container(width: 0.0,height: 0.0,),
);
}
//function used to send the user form to server
RaisedButton(
elevation: 7.0,
child: Text('Upload'),
textColor: Colors.white,
color: Colors.blue,
onPressed: () {
final StorageReference firebaseStorageRef =
FirebaseStorage.instance.ref().child(Username);
final StorageUploadTask task =
firebaseStorageRef.putFile(_image);
success(context);
},
),
//where success is a fuction
success(BuildContext context){
Navigator.of(context)
.push(MaterialPageRoute(builder:(context)=>Redirect() ));
}
不要在用户提交表单时推送新屏幕,而应弹出它,如下所示:
success(BuildContext context){
Navigator.of(context).pop();
}
这是因为你有一堆屏幕。当用户用完一个时,你应该把他送回你想要的地方,而不是把另一个放在最上面,把已经用过的留在栈上。
一旦我填写了表单并将其提交给 Firebase,代码就会将我导航到我的主页,但是当我按下 android phone 的后退按钮时,它会将用户发送到之前的表单包含所有先前填充数据的页面可用。我已经厌倦了使用 WillPopScope 函数来禁用我的 android phone 的后退按钮但没有响应..
我还使用 willpopscope 创建了一个函数并在 main 中调用它但没有结果。
@override
Widget build(BuildContext context) {
return new WillPopScope(
onWillPop: () async =>false,
child: new Scaffold(
appBar: new AppBar(
title: new Text('Welcome'),
actions: <Widget>[
_onbackpressed(), //tried disabling the back button by calling this fucntion
new FlatButton(
child: new Text('Logout',
style: new TextStyle(fontSize: 17.0, color: Colors.white)),
onPressed: _signOut)
],
),
body: _showTodoList(),
floatingActionButton: FloatingActionButton(
onPressed: () {
signupPage(context);
},
tooltip: 'Increment',
child: Icon(Icons.add),
)
),
);
}
//extra funtion to disable the back button-
_onbackpressed(){
return new WillPopScope(
onWillPop: () async =>false,
child: new Container(width: 0.0,height: 0.0,),
);
}
//function used to send the user form to server
RaisedButton(
elevation: 7.0,
child: Text('Upload'),
textColor: Colors.white,
color: Colors.blue,
onPressed: () {
final StorageReference firebaseStorageRef =
FirebaseStorage.instance.ref().child(Username);
final StorageUploadTask task =
firebaseStorageRef.putFile(_image);
success(context);
},
),
//where success is a fuction
success(BuildContext context){
Navigator.of(context)
.push(MaterialPageRoute(builder:(context)=>Redirect() ));
}
不要在用户提交表单时推送新屏幕,而应弹出它,如下所示:
success(BuildContext context){
Navigator.of(context).pop();
}
这是因为你有一堆屏幕。当用户用完一个时,你应该把他送回你想要的地方,而不是把另一个放在最上面,把已经用过的留在栈上。