Flutter 为什么Flatter在尝试注销应用程序时会在控制台中抛出NoSuchMethodError,即使它在模拟器中工作?
我正在为我的Flatter应用程序设置身份验证流,并且在模拟器中一切都很顺利。注册和注销都很有效。尽管在模拟器中工作,但在尝试注销时,Flatter会抛出一个NoSuchMethod错误 我的注销屏幕Flutter 为什么Flatter在尝试注销应用程序时会在控制台中抛出NoSuchMethodError,即使它在模拟器中工作?,flutter,firebase-authentication,flutter-navigation,Flutter,Firebase Authentication,Flutter Navigation,我正在为我的Flatter应用程序设置身份验证流,并且在模拟器中一切都很顺利。注册和注销都很有效。尽管在模拟器中工作,但在尝试注销时,Flatter会抛出一个NoSuchMethod错误 我的注销屏幕 class Logout extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( body: Center( child: Reu
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)),
),
注册中的相关代码
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
颤振:══╡ WIDGETS库捕获到异常
颤振:在构建开始时抛出以下NoSuchMethodError(脏,依赖项:[MediaQuery,
颤振:继承提供程序]:
颤振:在null上调用了getter“uid”。
颤振:接收器:空
颤振:尝试呼叫: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,
),
),
类开始扩展无状态小部件{
@凌驾
小部件构建(构建上下文){
字符串uid=Provider.of(context.uid);
SizeConfig().init(上下文);
回程多供应商(
供应商:[
StreamProvider.value(
值:数据库().generalDataStream(
uid,
),
),
谢谢你的帮助!我真的很感激你,因为我被困在这里了:)试着用auth代替AuthService(),因为auth是FirebaseAuth的实例,你应该从中注销。FirebaseAuth auth=FirebaseAuth.instance;
onPress: () async {
await auth.signOut();
Navigator.pushNamedAndRemoveUntil(
context, '/registration', (route) => false);
},
这不会改变任何事情。我已经在AuthService类中定义了方法signout。它只返回FirebaseAuth.signout()。您还有其他建议吗?:)如果尝试将FirebaseAuth.signout()设置为FirebaseAuth.instance.signout(),则返回Hi@th8m0s是的,对不起,我有。不幸的是,这个奇怪的错误仍然存在。请注意,当在模拟器内运行应用程序时,它可以完美地工作。错误只存在于控制台中。