gpt4 book ai didi

flutter - 有插曲和读取登录页面,然后进入管理页面 flutter

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

我尝试使我的应用程序(如果已登录)将进入管理页面,但是在进入管理页面之前,需要一秒钟的时间并阅读登录页面。我该怎么办?如果我在输入之前先加载,什么时候/什么周期的加载将停止?
这是我的代码

class _MyAppState extends State<MyApp> {
bool _isLoggedIn = false;

@override
void initState() {
_checkIfLoggedIn();
super.initState();
}


void _checkIfLoggedIn() async {
// check if token is there
SharedPreferences localStorage = await SharedPreferences.getInstance();
var token = localStorage.getString('api_token');
if(token!= null){
setState(() {
_isLoggedIn = true;
});
}
}

@override
Widget build(BuildContext context) {
final textTheme = Theme.of(context).textTheme;
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.red,
textTheme:GoogleFonts.latoTextTheme(textTheme).copyWith(
body1: GoogleFonts.montserrat(textStyle: textTheme.body1),
),
),
home:
_isLoggedIn ?
AdminMain()
:
LoginPage(),
);
}
}

最佳答案

我先加载,然后在initstate中先将_isLoggedin设置为true,然后将_isLoading设置为false

_isLoading ? loadingWidget(context)
:
(_isLoggedIn ?
AdminMain()
:
LoginPage()
),

关于flutter - 有插曲和读取登录页面,然后进入管理页面 flutter ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60679299/

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