gpt4 book ai didi

firebase - getter 'uid'在null上被调用

转载 作者:行者123 更新时间:2023-12-03 04:46:56 26 4
gpt4 key购买 nike

我的应用程序流程如下:

包装器->身份验证->登录

但是,当我运行该应用程序时,它会显示红屏和以下异常:

    The following NoSuchMethodError was thrown building Wrapper(dirty, dependencies: [InheritedProvider<User>], state: _WrapperState#fd39b):
The getter 'uid' was called on null.
Receiver: null
Tried calling: uid

我以前曾经运行过它,并且运行良好,但是我不为什么现在显示此异常:

enter image description here
这是主要的:
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return StreamProvider<User>.value(
value: AuthService().user,
child: MaterialApp(
title: 'Sayarty',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.green,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: Wrapper(),
),
);
}
}

这是包装器类:
    class Wrapper extends StatefulWidget {
@override
_WrapperState createState() => _WrapperState();
}

class _WrapperState extends State<Wrapper> {
int _currentTab = 1;

final _page = [
Search(),
Home(),
Account(),
];

@override
Widget build(BuildContext context) {
final user = Provider.of<User>(context);
print(user.uid);

if (user == null) {
return Authenticate();
} else {
return
// Home();
}
}

最佳答案

可能是因为现在您在测试print(user.uid);之前添加了if user is == null
将其放在else中:

//print(user.uid);

if (user == null) {
return Authenticate();
} else {
print(user.uid);
return
Home();
}

关于firebase - getter 'uid'在null上被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62122211/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com