chatting/lib/loading_page.dart

58 lines
1.6 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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 == 0){
Navigator.of(context).pushReplacementNamed("login");
}else{
loginStatus=1;
Navigator.of(context).pushReplacementNamed("app");
}
/*prefs.setInt('current_num', 999); //存储数据
var currentNum = prefs.getInt('current_num') ?? 0; //读取数据默认为0
print('读取数据 $currentNum');
prefs.remove('current_num');//删除数据
var delCurrentNum = prefs.getInt('current_num') ?? 0; //读取数据默认为0
print('删除数据 $delCurrentNum');*/
}
@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,),
],
),
);
}
}