Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f2ea4b4

Browse files
feat:请求loading
1 parent ba388eb commit f2ea4b4

File tree

2 files changed

+64
-45
lines changed

2 files changed

+64
-45
lines changed

‎flutter_github_login/lib/http/index.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'package:dio/dio.dart'
88
LogInterceptor,
99
Response;
1010
import 'package:flutter_github_login/utils/localStorage.dart' show LocalStorage;
11-
// import 'loading.dart' as AppLoading;
11+
import 'loading.dart' as AppLoading;
1212

1313
Dio getDio({options, loading}) {
1414
if (options == null) {
@@ -32,7 +32,7 @@ Dio getDio({options, loading}) {
3232
if (options.headers['Authorization'] == null && token != null) {
3333
options.headers['Authorization'] = 'token $token';
3434
}
35-
// await AppLoading.beforeRequest(options.uri, loading);
35+
await AppLoading.beforeRequest(options.uri, loading);
3636
print('=========【发送请求】Start============');
3737
print("请求地址 ${options.uri}");
3838
print("请求头 ${options.headers}");
@@ -46,13 +46,13 @@ Dio getDio({options, loading}) {
4646
print("请求头 ${response.statusCode}");
4747
print("返回值 ${response.data}");
4848
print('=========【请求成功】End============');
49-
// await AppLoading.afterResponse(response.request.uri, loading);
49+
await AppLoading.afterResponse(response.request.uri, loading);
5050
return response;
5151
},
5252
onError: (DioError e) async {
5353
print('e.request.uri=======================${e.request}');
54-
// if (e.request != null && e.request.uri != null)
55-
// await AppLoading.afterResponse(e.request.uri, loading);
54+
if (e.request != null && e.request.uri != null)
55+
await AppLoading.afterResponse(e.request.uri, loading);
5656
dynamic msg = e.message;
5757
dynamic code = 0; // 错误码
5858
dynamic status = e.type; // http请求状态

‎flutter_github_login/lib/main.dart

Lines changed: 59 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,34 @@ class _MainAppState extends State<MainApp> {
1414
@override
1515
void initState() {
1616
super.initState();
17-
Store.setStoreCtx(context);
17+
Store.setStoreCtx(context);// 初始化数据层
1818
}
1919

20+
@override
21+
Widget build(BuildContext context) {
22+
Store.value<UserModel>(context).getLocalUserInfo();
23+
return Store.connect<UserModel>(
24+
builder: (context, child, model) {
25+
return MaterialApp(
26+
title: 'Flutter Demo',
27+
theme: ThemeData(
28+
primarySwatch: Colors.blue,
29+
),
30+
home: HomePage(),
31+
);
32+
}
33+
);
34+
}
35+
}
36+
37+
38+
class HomePage extends StatefulWidget {
39+
@override
40+
_HomePageState createState() => _HomePageState();
41+
}
42+
43+
class _HomePageState extends State<HomePage> {
44+
2045
// 抽屉面板
2146
renderDrawer() {
2247
return Drawer(
@@ -88,52 +113,46 @@ class _MainAppState extends State<MainApp> {
88113

89114
@override
90115
Widget build(BuildContext context) {
91-
Store.value<UserModel>(context).getLocalUserInfo();
116+
Store.setWidgetCtx(context); // 初始化scaffold的上下文作为全局上下文,提供弹框等使用
92117
return Store.connect<UserModel>(
93118
builder: (context, child, model) {
94-
return MaterialApp(
95-
title: 'Flutter Demo',
96-
theme: ThemeData(
97-
primarySwatch: Colors.blue,
119+
return Scaffold(
120+
appBar: AppBar(
121+
title: Text('Flutter UI 接入github登陆'),
98122
),
99-
home: Scaffold(
100-
appBar: AppBar(
101-
title: Text('Flutter UI 接入github登陆'),
102-
),
103-
body: Center(
104-
child: Column(
105-
mainAxisAlignment: MainAxisAlignment.center,
106-
children: <Widget>[
107-
model.showLogin ?
108-
AppLogin()
109-
:
110-
ListTile(
111-
leading: ClipOval(
112-
child: model.user.avatar_url != null
113-
? Image.network(
114-
model.user.avatar_url,
115-
width: 80,
116-
)
117-
: Icon(Icons.account_box),
118-
),
119-
title: Text(
120-
model.user.name ?? 'Guest',
121-
style: TextStyle(fontWeight: FontWeight.bold)
122-
),
123-
onTap: () {
124-
// Scaffold.of(context).openDrawer()
125-
if(model.user.avatar_url == null) {
126-
model.changeShowLogin(true);
127-
}
123+
body: Center(
124+
child: Column(
125+
mainAxisAlignment: MainAxisAlignment.center,
126+
children: <Widget>[
127+
model.showLogin ?
128+
AppLogin()
129+
:
130+
ListTile(
131+
leading: ClipOval(
132+
child: model.user.avatar_url != null
133+
? Image.network(
134+
model.user.avatar_url,
135+
width: 80,
136+
)
137+
: Icon(Icons.account_box),
138+
),
139+
title: Text(
140+
model.user.name ?? 'Guest',
141+
style: TextStyle(fontWeight: FontWeight.bold)
142+
),
143+
onTap: () {
144+
// Scaffold.of(context).openDrawer()
145+
if(model.user.avatar_url == null) {
146+
model.changeShowLogin(true);
128147
}
129-
)
130-
],
131-
),
148+
}
149+
)
150+
],
132151
),
133-
drawer: renderDrawer(),
134152
),
153+
drawer: renderDrawer(),
135154
);
136155
}
137156
);
138157
}
139-
}
158+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /