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