chatting/lib/loading_page.dart

50 lines
1.3 KiB
Dart
Raw Normal View History

2020-06-06 10:06:54 +00:00
import 'package:flutter/material.dart';
2020-06-09 10:36:07 +00:00
import 'package:shared_preferences/shared_preferences.dart';
2020-06-06 10:06:54 +00:00
/**
*
*/
class LoadingPage extends StatefulWidget {
@override
_LoadingPageState createState() => _LoadingPageState();
}
class _LoadingPageState extends State<LoadingPage> {
2020-06-09 10:36:07 +00:00
//0 未登录 ,1 已登录
void initData() async {
final prefs = await SharedPreferences.getInstance(); //获取SP的实例
int loginStatus=prefs.getInt('loginStatus') ?? 0;
print(prefs.getInt('current_num'));
2020-06-10 10:27:55 +00:00
if(loginStatus == 1){
2020-06-09 10:36:07 +00:00
Navigator.of(context).pushReplacementNamed("login");
}else{
loginStatus=1;
Navigator.of(context).pushReplacementNamed("app");
}
}
2020-06-06 10:06:54 +00:00
@override
void initState() {
super.initState();
//加载页默认停留三秒
Future.delayed(Duration(seconds: 3),(){
print("仿微信app页面正在加载中");
2020-06-09 09:35:43 +00:00
//判断是否登录,如果没有登陆则跳转至登录页,如果登录则跳转至聊天页
2020-06-09 10:36:07 +00:00
initData();
2020-06-06 10:06:54 +00:00
});
}
@override
Widget build(BuildContext context) {
return new Center(
child: Stack(
children: <Widget>[
//加载页面居中背景图使用 cover 模式
Image. asset("assets/images/loading.jpg", fit: BoxFit.cover,),
],
),
);
}
}