firebase - Flutter firebase静默登录不起作用
问题描述
我正在使用firebase auth开发一个带有flutter的webapp。我需要一个静默登录功能。这就是我尝试过的:我在 main.dart 中的构建方法:
return user != null
? FutureBuilder(
future: widget._userRepo.getUserById(user.uid),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (user != null) {
BlocProvider.of<SignInCubit>(context)
.setInitialUserData(snapshot.data);
}
return MaterialApp(
title: 'Name',
theme: ThemeData(
highlightColor: CustomColours.darkBlue,
primarySwatch: Colors.blue,
textTheme: Theme.of(context).textTheme.apply(
bodyColor: Colors.white,
fontFamily: 'FuturaLight')),
home: width > height
? /*CodePage(_gameRepo, _heroRepo, _tournamentRepo, _userRepo,
"123456", _teamRepo)*/
LandingPage(
widget._tournamentRepo,
widget._userRepo,
widget._gameRepo,
widget._heroRepo,
widget._teamRepo)
: NoMobilePage());
}
if (snapshot.connectionState == ConnectionState.waiting) {
return Container();
} else {
return Container();
}
})
: MaterialApp(
title: 'Name',
theme: ThemeData(
highlightColor: CustomColours.darkBlue,
primarySwatch: Colors.blue,
textTheme: Theme.of(context)
.textTheme
.apply(bodyColor: Colors.white, fontFamily: 'FuturaLight')),
home: width > height
? /*CodePage(_gameRepo, _heroRepo, _tournamentRepo, _userRepo,
"123456", _teamRepo)*/
LandingPage(widget._tournamentRepo, widget._userRepo,
widget._gameRepo, widget._heroRepo, widget._teamRepo)
: NoMobilePage());
hte userRepo 中的方法:
Future<CustomUser> getUserById(String id) async {
final Map<String, dynamic> userData =
await _userDataService.getUserById(id);
if (userData == null) {
return null;
} else {
return CustomUser.fromJson(userData);
}
}
用户服务:
Future<Map<String, dynamic>> getUserById(String id) async {
if (id == null) {
return null;
}
DocumentSnapshot document =
await _firebaseFirestore.collection(_collectionPath).doc(id).get();
return document.data();
我从这里获取用户,在 main.dart 中:
class _MyAppState extends State<MyApp> {
Future<User> user;
@override
void initState() {
user = widget._googleSignInRepo.getUser();
super.initState();
}
这是 getUser 函数:
User getUser() {
return _googleAuthService.getUser();
}
但是,当我运行它时,用户变量是一个错误:“<getObject: NoSuchMethodError: The getter 'uri' was called on null.>”。我做错了什么?谢谢
解决方案
推荐阅读
- proget - ProGet 资产注册表无法识别 API 密钥
- javascript - 如果 CSS 中存在 3 个以上的元素,如何在新行中自动格式化?
- sql - SQL 视图/函数/Select 语句中的变量
- reactjs - 如何将“this”与 setState 回调绑定
- javascript - 为什么使用Jquery draggable随着容器宽度的增加拖动速度会变慢?
- flutter - 我应该调用 super.dispose() 吗?
- python - 在进行合并时重塑熊猫数据框
- reactjs - 为什么我不能用数组传递道具
- java - 循环对象数组并在 JSP 中使用 c:if jstl
- javascript - IE8 Style 不支持 setProperty 方法