Skip to content

Commit 15835bf

Browse files
committed
增加用户信息的本地存储
1 parent fb74356 commit 15835bf

3 files changed

Lines changed: 144 additions & 11 deletions

File tree

‎lib/common/dao/UserDao.dart‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ class UserDao {
4848
static initUserInfo() async {
4949
var token = await LocalStorage.get(Config.TOKEN_KEY);
5050
var res = await getUserInfoLocal();
51-
if (res && res.result && token) {
52-
//todo store
51+
if (res != null && res.result && token != null) {
52+
//todo dispatch store
5353
}
5454
return new DataResult(res.data, (res.result && (token != null)));
5555
}
@@ -58,8 +58,9 @@ class UserDao {
5858
static getUserInfoLocal() async {
5959
var userText = await LocalStorage.get(Config.USER_INFO);
6060
if (userText != null) {
61-
var res = json.decode(userText);
62-
return new DataResult(res.data, true);
61+
var userMap = json.decode(userText);
62+
User user = User.fromJson(userMap);
63+
return new DataResult(user, true);
6364
} else {
6465
return new DataResult(null, false);
6566
}

‎lib/common/model/User.g.dart‎

Lines changed: 132 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/page/WelcomePage.dart‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import 'dart:async';
22

33
import 'package:flutter/material.dart';
4+
import 'package:gsy_github_app_flutter/common/dao/UserDao.dart';
45
import 'package:gsy_github_app_flutter/page/HomePage.dart';
56
import 'package:gsy_github_app_flutter/page/LoginPage.dart';
67

78
class WelcomePage extends StatelessWidget {
89
@override
910
Widget build(BuildContext context) {
10-
1111
toNext(res) {
1212
Widget widget;
1313
if (res != null && res.result) {
@@ -20,14 +20,14 @@ class WelcomePage extends StatelessWidget {
2020
return widget;
2121
}));
2222
}
23-
// 一秒以后将任务添加至event队列
23+
2424
new Future.delayed(const Duration(seconds: 2), () {
25-
Navigator.of(context).pushReplacement(new MaterialPageRoute(builder: (context) {
26-
//判断是去登录还是主页
27-
return new LoginPage();
28-
}));
25+
UserDao.initUserInfo().then((res) {
26+
print("Ffffffffff");
27+
print(res);
28+
toNext(res);
29+
});
2930
});
30-
3131
return new Container(
3232
color: Colors.white,
3333
child: new Center(

0 commit comments

Comments
 (0)