Skip to content

Commit 46fbd4e

Browse files
committed
fix:修复登录loading窗口问题
1 parent 1e062e5 commit 46fbd4e

File tree

7 files changed

+36
-34
lines changed

7 files changed

+36
-34
lines changed

lib/controller/index.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ void initState() {
77
// 获取版本号
88
Store.valueNotCtx<ConfigModel>().$getAppVersion();
99
// 登录
10-
Store.valueNotCtx<UserModel>().$getLocalUserInfo();
10+
Store.valueNotCtx<UserModel>().getLocalUserInfo();
1111
Future.delayed(Duration(seconds: 3), () {
1212
AppVersion().check(Store.widgetCtx);
1313
});

lib/http/loading.dart

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:efox_flutter/store/index.dart' show Store;
33

4+
45
bool loading = false;
56
Set dict = Set();
67

@@ -46,6 +47,11 @@ class LoadingDialog extends StatefulWidget {
4647
}
4748

4849
class LoadingDialogState extends State<LoadingDialog> {
50+
51+
@override
52+
void initState() {
53+
super.initState();
54+
}
4955
@override
5056
Widget build(BuildContext context) {
5157
return Scaffold(
@@ -78,9 +84,9 @@ class LoadingDialogState extends State<LoadingDialog> {
7884
}
7985

8086
@override
81-
void dispose() {
82-
super.dispose();
83-
loading = false;
84-
dict.clear();
87+
void dispose() async {
88+
await super.dispose();
89+
// loading = false;
90+
// await dict.clear();
8591
}
8692
}

lib/page/app_login/index.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class _IndexState extends State<Index> {
133133
if ((_formKey.currentState as FormState)
134134
.validate()) {
135135
await Store.value<UserModel>(context)
136-
.$loginController(context, {
136+
.loginController(context, {
137137
'name': nameCtl.text.trim(),
138138
'pwd': pwdCtl.text.trim()
139139
});

lib/page/home.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class _IndexState extends State<Index> {
5454
leading: Icon(Icons.exit_to_app),
5555
title: Text(AppLocalizations.$t('common.logout')),
5656
onTap: () {
57-
Store.value<UserModel>(context).$clearUserInfo();
57+
Store.value<UserModel>(context).clearUserInfo();
5858
},
5959
),
6060
];

lib/store/models/user_model.dart

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,23 @@ import '../objects/user_info.dart' show UserInfo;
66
import '../objects/github_resp_info.dart' show GitHubRespInfo;
77
import 'package:efox_flutter/http/index.dart' as Http;
88
import 'package:efox_flutter/utils/localStorage.dart' show LocalStorage;
9-
import 'package:efox_flutter/http/loading.dart' as Loading;
109

1110
class UserModel with ChangeNotifier {
1211
UserInfo user = UserInfo();
1312
Future testLogin() async {
14-
await Loading.beforeRequest('aaa', {});
15-
return Future.delayed(Duration(seconds: 3), () async {
16-
await Loading.afterResponse('aaa', {});
17-
print("返回中");
13+
return await Http.post(url: 'http://www.baidu.com').then((res) {
1814
return true;
15+
}).catchError((error) async {
16+
return await getUserInfo();
1917
});
2018
}
2119

2220
/**
2321
* 登录控制
2422
*/
25-
Future $loginController(context, payload) async {
26-
dynamic result = await $login(payload);
23+
Future loginController(context, payload) async {
24+
dynamic result = await login(payload);
25+
// dynamic result = await testLogin();
2726
print('返回result $result');
2827
if (result == true) {
2928
print('登录成功后退');
@@ -36,7 +35,7 @@ class UserModel with ChangeNotifier {
3635
}
3736
}
3837

39-
Future $login(payload) async {
38+
Future login(payload) async {
4039
var name = payload['name'];
4140
var pwd = payload['pwd'];
4241
var bytes = utf8.encode("$name:$pwd");
@@ -54,56 +53,56 @@ class UserModel with ChangeNotifier {
5453
options: options,
5554
);
5655
return await response.then((resp) async {
57-
await $setLoginRespInfo(resp.data);
58-
return true;
56+
return await setLoginRespInfo(resp.data);
5957
}).catchError((error) {
60-
$clearUserInfo();
58+
clearUserInfo();
6159
return false;
6260
});
6361
}
6462

65-
$setLoginRespInfo(payload) async {
63+
setLoginRespInfo(payload) async {
6664
GitHubRespInfo user = GitHubRespInfo.fromJson(payload);
6765
LocalStorage.set('githubRespInfo', user.toString());
6866
print('user.token.toString() ${user.token.toString()}');
6967
LocalStorage.set('githubRespLoginToken', user.token.toString());
70-
await $getUserInfo(); // 授权成功获取用户信息
68+
return await getUserInfo(); // 授权成功获取用户信息
7169
}
7270

7371
/**
7472
* 授权成功或打开app时获取用户信息
7573
*/
76-
Future $getUserInfo() async {
74+
Future getUserInfo() async {
7775
var response = Http.post(
7876
url: 'https://api.github.com/user',
7977
);
80-
await response.then((resp) {
78+
return await response.then((resp) {
8179
UserInfo user = UserInfo.fromJson(resp.data);
82-
$setUserInfo(user);
80+
setUserInfo(user);
81+
return true;
8382
}).catchError((error) {
8483
print('ERROR $error');
85-
// $clearUserInfo();
84+
return false;
8685
});
8786
}
8887

8988
/**
9089
* 获取本地数据,减少调用接口
9190
*/
92-
$getLocalUserInfo() async {
91+
getLocalUserInfo() async {
9392
String data = await LocalStorage.get('githubUserInfo');
9493
print("本地数据 $data");
9594
if (data == null) {
96-
$getUserInfo();
95+
getUserInfo();
9796
return;
9897
}
9998
UserInfo user = UserInfo.fromJson(json.decode(data));
100-
$setUserInfo(user);
99+
setUserInfo(user);
101100
}
102101

103102
/**
104103
* 设置用户信息
105104
*/
106-
$setUserInfo(payload) {
105+
setUserInfo(payload) {
107106
user = payload;
108107
if (user != null && user.id != null) {
109108
LocalStorage.set('githubUserInfo', json.encode(user));
@@ -114,7 +113,7 @@ class UserModel with ChangeNotifier {
114113
/**
115114
* 清空用户信息
116115
*/
117-
$clearUserInfo() {
116+
clearUserInfo() {
118117
user = UserInfo();
119118
LocalStorage.remove('githubUserInfo');
120119
LocalStorage.remove('githubRespInfo');

lib/store/objects/github_resp_info.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class GitHubRespInfo extends Object {
3333
GitHubRespInfo.fromJson(json) {
3434
id = json['id'];
3535
url = json['url'];
36-
app = json['app'];
36+
app = App.fromJson(json['app']);
3737
token = json['token'];
3838
hashed_token = json['hashed_token'];
3939
token_last_eight = json['token_last_eight'];
@@ -48,7 +48,7 @@ class GitHubRespInfo extends Object {
4848
Map<String, dynamic> toJson() => {
4949
'id': id,
5050
'url': url,
51-
'app': App.fromJson(app),
51+
'app': app,
5252
'token': token,
5353
'hashed_token': hashed_token,
5454
'token_last_eight': token_last_eight,

lib/store/objects/user_info.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,6 @@ class Plan extends Object {
179179

180180
Plan.fromJson(instance) {
181181
if (instance != null) {
182-
if (instance.runtimeType == String) {
183-
instance = json.decode(instance);
184-
}
185182
name = instance['name'];
186183
space = instance['space'];
187184
collaborators = instance['collaborators'];

0 commit comments

Comments
 (0)