ios - Flutter中的错误:flutter:错误:NoSuchMethodError:方法'findAncestorStateOfType'在null上被调用
问题描述
一旦用户通过 firebase 身份验证,我将返回 UID,但随后无法打开主页。我可以在控制台上打印用户 IF 但它没有转移到下一页
验证和提交()异步{
if (validateandSave()) {
try {
FirebaseUser user = (await FirebaseAuth.instance
.signInWithEmailAndPassword(email: _email, password: _password))
.user;
print('User is valid and saved');
print('Loggedin: USerId ${user.uid}');
Navigator.of(context).pushReplacementNamed('/home');
} catch (e) {
print('Error : $e');
}
}
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Fint'),
),
body: Container(
padding: EdgeInsets.all(16.0),
child: new Form(
key: formKey,
child: new Column(children: <Widget>[
new TextFormField(
decoration: new InputDecoration(labelText: 'Email'),
validator: (value) =>
value.isEmpty ? 'Email cannot be empty' : null,
onSaved: (value) => _email = value,
),
new TextFormField(
decoration: new InputDecoration(labelText: 'Password'),
validator: (value) =>
value.isEmpty ? 'Password cannot be empty' : null,
onSaved: (value) => _password = value,
obscureText: true,
),
new RaisedButton(
child: Text('Login'),
onPressed: validateandSubmit
),
]))));
}
}
解决方案
尝试这个
Navigator.pushReplacement(context, MaterialPageRoute(builder: (BuildContext context) => Home()));
推荐阅读
- node.js - 如何从表单中获取值以在 AdonisJs 中进行查询?
- r - 如何以优雅的方式将每组变量的平均值添加到列中?
- php - 在 python sys.argv 中不打印圆括号
- python - 比较两个url,通过读取python中page的内容,看看是否可以进行路径遍历
- sql - SQL:忽略 WHERE 子句中的条件
- angular - 如何从 URL 中唯一键标识的 Firebase 中检索数据?
- python - 多个列上的多个聚合
- sorting - 有没有办法让单元格在日期过去后更改日期?
- java - Java spring - “所需的int参数不存在”
- perl - 我可以通过 ssh 将本地变量回显到远程文件中吗?