【发布时间】:2020-12-19 11:07:23
【问题描述】:
有谁知道为什么我得到了失败的断言:布尔表达式不能为空。 如果我已经登录并退出应用程序并再次打开应用程序,我应该直接在主屏幕中。
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
class MyApp extends StatefulWidget {
// This widget is the root of your application.
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool userIsLoggedIn = false;
@override
void initState(){
getLoggedInState();
super.initState();
}
getLoggedInState()async{
await HelperFunction.getUserLoggedInSharedPreference().then((value){
setState(() {
userIsLoggedIn = value;
});
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: userIsLoggedIn ? HomeScreen() : CompanyLoadingBar(),
);
}
}
【问题讨论】:
-
检查调用堆栈。如果尚未设置登录偏好怎么办?
-
@ThienLD 你能在你用代码显示的地方发布一个答案吗?