我正在为我的 Flutter 应用程序设置身份验证流程,并且在模拟器中一切正常。SignUp 运行良好,SignOut 也运行良好。尽管在模拟器中工作,flutter 在尝试注销时会抛出 NoSuchMethod 错误。
我的注销屏幕
class Logout extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ReusableCard(
margin: EdgeInsets.all(20.0),
cardChild: Padding(
padding: EdgeInsets.all(100.0),
child: ReusableCard(
cardChild: Text('Log out'),
hexcolor: Colors.blueAccent,
onPress: () async {
await AuthService().signOut();
Navigator.pushNamedAndRemoveUntil(
context, '/registration', (route) => false);
},
),
),
),
),
);
}
}
注册相关代码
void initState() {
super.initState();
auth.getUser.then(
(user) {
if (user != null) {
Navigator.pushReplacementNamed(context, '/proddy');
}
},
);
}
FlatButton(
child: Text('Sign Up'),
onPressed: () async {
emailValid = validator.email(email);
passwordValid = validator.password(password);
if (emailValid == true && passwordValid == true) {
FirebaseUser user = await auth.createUserWithEmail(
email: email,
password: password,
);
if (user != null) {
await auth.updateUserData(user);
Navigator.pushReplacementNamed(context, '/start');
}
} else {
print('Your credentials are invalid');
}
},
color: Colors.greenAccent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0)),
),
错误信息
flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY
flutter: The following NoSuchMethodError was thrown building Start(dirty, dependencies: [MediaQuery,
flutter: InheritedProvider<FirebaseUser>]):
flutter: The getter 'uid' was called on null.
flutter: Receiver: null
flutter: Tried calling: uid
与错误有关的代码
class Start extends StatelessWidget {
@override
Widget build(BuildContext context) {
String uid = Provider.of<FirebaseUser>(context).uid;
SizeConfig().init(context);
return MultiProvider(
providers: [
StreamProvider<GeneralInformation>.value(
value: Database().generalDataStream(
uid,
),
),
感谢您提供任何帮助!我真的很感激,因为我几乎被困在这里:)