У меня есть следующие методы, чтобы увидеть, если пользователь уже вошел в систему, который в этом случае я вошел в систему, и функция getCurrentUser()
работает, потому что в консоли он возвращает «USER IS NOT NULL», но домашний виджетвсе еще нулевой, давая мне «ИСКЛЮЧЕНИЕ, ЗАПИСАННОЕ БИБЛИОТЕКОЙ ВИДЖЕТОВ», говорящее, что дом не может быть нулевым и прочим.
userAPI.dart
Future<FirebaseUser> getCurrentUser() async {
FirebaseUser user = await FirebaseAuth.instance.currentUser();
if (user != null) {
return user;
} else {
return null;
}
}
main.dart
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
Widget home;
APIs().usersAPI.getCurrentUser().then((u) {
if (u == null) {
print('USER IS NULL');
home = WelcomePage();
} else {
print('USER IS NOT NULL');
home = FeedPage();
}
});
return MaterialApp(
title: "Jedi",
debugShowCheckedModeBanner: false,
home: home,
routes: {
'/login' : (context) => new LoginPage(),
'/feed' : (context) => new FeedPage(),
},
);
}
}