Skip to content

Commit 44ac476

Browse files
committed
load more text
1 parent 404ec75 commit 44ac476

8 files changed

Lines changed: 109 additions & 101 deletions

File tree

‎lib/common/dao/EventDao.dart‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
import 'package:gsy_github_app_flutter/common/dao/DaoResult.dart';
23
import 'package:gsy_github_app_flutter/common/model/User.dart';
34
import 'package:gsy_github_app_flutter/common/net/Address.dart';
@@ -57,4 +58,9 @@ class EventDao {
5758
}
5859
}
5960

61+
static clearEvent(Store store) {
62+
store.state.eventList.clear();
63+
store.dispatch(new RefreshEventAction([]));
64+
}
65+
6066
}

‎lib/common/dao/UserDao.dart‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import 'package:gsy_github_app_flutter/widget/UserItem.dart';
1515
import 'package:redux/redux.dart';
1616

1717
class UserDao {
18-
static login(userName, password, callback) async {
18+
static login(userName, password, store) async {
1919
String type = userName + ":" + password;
2020
var bytes = utf8.encode(type);
2121
var base64Str = base64.encode(bytes);
@@ -34,6 +34,7 @@ class UserDao {
3434
HttpManager.clearAuthorization();
3535

3636
var res = await HttpManager.netFetch(Address.getAuthorization(), json.encode(requestParams), null, new Options(method: "post"));
37+
var resultData = null;
3738
if (res != null && res.result) {
3839
await LocalStorage.save(Config.PW_KEY, password);
3940
var resultData = await getUserInfo(null);
@@ -42,10 +43,9 @@ class UserDao {
4243
print(resultData.data);
4344
print(res.data.toString());
4445
}
46+
store.dispatch(new UpdateUserAction(resultData.data));
4547
}
46-
if (callback != null) {
47-
callback(res);
48-
}
48+
return new DataResult(resultData, res.result);
4949
}
5050

5151
///初始化用户信息
@@ -80,7 +80,7 @@ class UserDao {
8080
}
8181
if (res != null && res.result) {
8282
String starred = "---";
83-
if(res.data["type"] != "Organization") {
83+
if (res.data["type"] != "Organization") {
8484
var countRes = await getUserStaredCountNet(res.data["login"]);
8585
if (countRes.result) {
8686
starred = countRes.data;
@@ -97,9 +97,10 @@ class UserDao {
9797
}
9898
}
9999

100-
static clearAll() async {
100+
static clearAll(Store store) async {
101101
HttpManager.clearAuthorization();
102102
LocalStorage.remove(Config.USER_INFO);
103+
store.dispatch(new UpdateUserAction(User.empty()));
103104
}
104105

105106
/**
@@ -199,11 +200,10 @@ class UserDao {
199200
return res;
200201
}
201202

202-
203203
/**
204204
* 设置所有通知已读
205205
*/
206-
static setAllNotificationAsReadDao () async {
206+
static setAllNotificationAsReadDao() async {
207207
String url = Address.setAllNotificationAsRead();
208208
var res = await HttpManager.netFetch(url, null, null, new Options(method: "PUT", contentType: ContentType.TEXT));
209209
return new DataResult(res.data, res.result);

‎lib/common/style/GSYStyle.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ class GSYStrings {
215215
static const String network_error = "网络错误";
216216

217217
static const String load_more_not = "没有更多数据";
218+
static const String load_more_text = "正在加载更多";
218219

219220
static const String home_dynamic = "动态";
220221
static const String home_trend = "趋势";

‎lib/page/DynamicPage.dart‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,6 @@ class _DynamicPageState extends GSYListState<DynamicPage> {
8484
super.didChangeDependencies();
8585
}
8686

87-
88-
@override
89-
clearData() {
90-
super.clearData();
91-
if( _getStore().state.eventList != null) {
92-
_getStore().state.eventList.clear();
93-
}
94-
}
95-
96-
@override
97-
void dispose() {
98-
super.dispose();
99-
clearData();
100-
}
101-
10287
_renderEventItem(EventViewModel e) {
10388
return new EventItem(
10489
e,

‎lib/page/LoginPage.dart‎

Lines changed: 68 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
import 'dart:async';
2+
13
import 'package:flutter/material.dart';
4+
import 'package:flutter_redux/flutter_redux.dart';
25
import 'package:gsy_github_app_flutter/common/config/Config.dart';
36
import 'package:gsy_github_app_flutter/common/dao/UserDao.dart';
47
import 'package:gsy_github_app_flutter/common/local/LocalStorage.dart';
8+
import 'package:gsy_github_app_flutter/common/redux/GSYState.dart';
59
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
610
import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
711
import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart';
@@ -14,8 +18,7 @@ import 'package:gsy_github_app_flutter/widget/GSYInputWidget.dart';
1418
* Date: 2018-07-16
1519
*/
1620
class LoginPage extends StatefulWidget {
17-
18-
static final String sName = "login";
21+
static final String sName = "login";
1922

2023
@override
2124
State createState() {
@@ -42,76 +45,80 @@ class _LoginPageState extends State<LoginPage> {
4245
initParams() async {
4346
_userName = await LocalStorage.get(Config.USER_NAME_KEY);
4447
_password = await LocalStorage.get(Config.PW_KEY);
45-
if(_userName != null) {
48+
if (_userName != null) {
4649
userController.value = new TextEditingValue(text: _userName);
4750
}
48-
if(_password != null) {
51+
if (_password != null) {
4952
pwController.value = new TextEditingValue(text: _password);
5053
}
5154
}
5255

5356
@override
5457
Widget build(BuildContext context) {
55-
return new Container(
56-
color: Color(GSYColors.primaryValue),
57-
child: new Center(
58-
child: new Card(
59-
elevation: 5.0,
60-
shape: new RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(10.0))),
61-
color: Color(GSYColors.cardWhite),
62-
margin: const EdgeInsets.all(30.0),
63-
child: new Padding(
64-
padding: new EdgeInsets.only(left: 30.0, top: 40.0, right: 30.0, bottom: 80.0),
65-
child: new Column(
66-
mainAxisAlignment: MainAxisAlignment.center,
67-
mainAxisSize: MainAxisSize.min,
68-
children: <Widget>[
69-
new Image(image: new AssetImage('static/images/logo.png'), width: 90.0, height: 90.0),
70-
new Padding(padding: new EdgeInsets.all(10.0)),
71-
new GSYInputWidget(
72-
hintText: GSYStrings.login_username_hint_text,
73-
iconData: GSYICons.LOGIN_USER,
74-
onChanged: (String value) {
75-
_userName = value;
76-
},
77-
controller: userController,
78-
),
79-
new Padding(padding: new EdgeInsets.all(10.0)),
80-
new GSYInputWidget(
81-
hintText: GSYStrings.login_password_hint_text,
82-
iconData: GSYICons.LOGIN_PW,
83-
obscureText: true,
84-
onChanged: (String value) {
85-
_password = value;
86-
},
87-
controller: pwController,
88-
),
89-
new Padding(padding: new EdgeInsets.all(30.0)),
90-
new GSYFlexButton(
91-
text: GSYStrings.login_text,
92-
color: Color(GSYColors.primaryValue),
93-
textColor: Color(GSYColors.textWhite),
94-
onPress: () {
95-
if (_userName == null || _userName.length == 0) {
96-
return;
97-
}
98-
if (_password == null || _password.length == 0) {
99-
return;
100-
}
101-
CommonUtils.showLoadingDialog(context);
102-
UserDao.login(_userName, _password, (data) {
103-
Navigator.pop(context);
104-
if (data != null && data.result == true) {
105-
NavigatorUtils.goHome(context);
58+
return new StoreBuilder<GSYState>(builder: (context, store) {
59+
return new Container(
60+
color: Color(GSYColors.primaryValue),
61+
child: new Center(
62+
child: new Card(
63+
elevation: 5.0,
64+
shape: new RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(10.0))),
65+
color: Color(GSYColors.cardWhite),
66+
margin: const EdgeInsets.all(30.0),
67+
child: new Padding(
68+
padding: new EdgeInsets.only(left: 30.0, top: 40.0, right: 30.0, bottom: 80.0),
69+
child: new Column(
70+
mainAxisAlignment: MainAxisAlignment.center,
71+
mainAxisSize: MainAxisSize.min,
72+
children: <Widget>[
73+
new Image(image: new AssetImage('static/images/logo.png'), width: 90.0, height: 90.0),
74+
new Padding(padding: new EdgeInsets.all(10.0)),
75+
new GSYInputWidget(
76+
hintText: GSYStrings.login_username_hint_text,
77+
iconData: GSYICons.LOGIN_USER,
78+
onChanged: (String value) {
79+
_userName = value;
80+
},
81+
controller: userController,
82+
),
83+
new Padding(padding: new EdgeInsets.all(10.0)),
84+
new GSYInputWidget(
85+
hintText: GSYStrings.login_password_hint_text,
86+
iconData: GSYICons.LOGIN_PW,
87+
obscureText: true,
88+
onChanged: (String value) {
89+
_password = value;
90+
},
91+
controller: pwController,
92+
),
93+
new Padding(padding: new EdgeInsets.all(30.0)),
94+
new GSYFlexButton(
95+
text: GSYStrings.login_text,
96+
color: Color(GSYColors.primaryValue),
97+
textColor: Color(GSYColors.textWhite),
98+
onPress: () {
99+
if (_userName == null || _userName.length == 0) {
100+
return;
101+
}
102+
if (_password == null || _password.length == 0) {
103+
return;
106104
}
107-
});
108-
},
109-
)
110-
],
105+
CommonUtils.showLoadingDialog(context);
106+
UserDao.login(_userName, _password, store).then((res) {
107+
Navigator.pop(context);
108+
if (res != null && res.result) {
109+
new Future.delayed(const Duration(seconds: 1), () {
110+
NavigatorUtils.goHome(context);
111+
});
112+
}
113+
});
114+
},
115+
)
116+
],
117+
),
111118
),
112119
),
113120
),
114-
),
115-
);
121+
);
122+
});
116123
}
117124
}

‎lib/widget/GSYListState.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ abstract class GSYListState<T extends StatefulWidget> extends State<T> with Auto
124124
@override
125125
void dispose() {
126126
isShow = false;
127+
isLoading = false;
127128
super.dispose();
128129
}
129130
}

‎lib/widget/GSYPullLoadWidget.dart‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
import 'dart:async';
2-
31
import 'package:flutter/material.dart';
4-
import 'package:flutter_redux/flutter_redux.dart';
5-
import 'package:gsy_github_app_flutter/common/model/User.dart';
6-
import 'package:gsy_github_app_flutter/common/redux/GSYState.dart';
7-
import 'package:gsy_github_app_flutter/common/redux/UserRedux.dart';
2+
import 'package:flutter_spinkit/flutter_spinkit.dart';
83
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
94

105
///通用下上刷新控件
@@ -87,7 +82,16 @@ class _GSYPullLoadWidgetState extends State<GSYPullLoadWidget> {
8782
}
8883

8984
Widget _buildProgressIndicator() {
90-
Widget bottomWidget = (control.needLoadMore) ? new CircularProgressIndicator() : new Text(GSYStrings.load_more_not);
85+
Widget bottomWidget = (control.needLoadMore)
86+
? new Row(mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[
87+
new SpinKitRotatingCircle(color: Color(GSYColors.primaryValue)),
88+
new Container(width: 5.0,),
89+
new Text(
90+
GSYStrings.load_more_text,
91+
style: GSYConstant.smallTextBold,
92+
)
93+
])
94+
: new Text(GSYStrings.load_more_not, style: GSYConstant.smallTextBold);
9195
return new Padding(
9296
padding: const EdgeInsets.all(20.0),
9397
child: new Center(

‎lib/widget/HomeDrawer.dart‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_redux/flutter_redux.dart';
3+
import 'package:gsy_github_app_flutter/common/dao/EventDao.dart';
34
import 'package:gsy_github_app_flutter/common/dao/IssueDao.dart';
45
import 'package:gsy_github_app_flutter/common/dao/UserDao.dart';
56
import 'package:gsy_github_app_flutter/common/model/User.dart';
@@ -26,11 +27,11 @@ class HomeDrawer extends StatelessWidget {
2627
new UserAccountsDrawerHeader(
2728
//Material内置控件
2829
accountName: new Text(
29-
user.login,
30+
user.login != null ? user.login : "---",
3031
style: GSYConstant.largeTextWhite,
3132
),
3233
accountEmail: new Text(
33-
user.email != null ? user.email : user.name,
34+
user.email != null ? user.email : user.name != null ? user.name : "---",
3435
style: GSYConstant.subNormalText,
3536
),
3637
//用户名
@@ -40,7 +41,7 @@ class HomeDrawer extends StatelessWidget {
4041
onTap: () {},
4142
child: new CircleAvatar(
4243
//圆形图标控件
43-
backgroundImage: new NetworkImage(user.avatar_url),
44+
backgroundImage: new NetworkImage(user.avatar_url != null ? user.avatar_url : "---"),
4445
),
4546
),
4647
decoration: new BoxDecoration(
@@ -74,21 +75,24 @@ class HomeDrawer extends StatelessWidget {
7475
style: GSYConstant.normalText,
7576
),
7677
onTap: () {
77-
showDialog(context: context, builder: (BuildContext context) => AboutDialog(
78-
applicationName :GSYStrings.app_name,
79-
applicationVersion: "1.0.0",
80-
applicationIcon: new Image(image: new AssetImage('static/images/logo.png'), width: 50.0, height: 50.0),
81-
applicationLegalese: null,
82-
));
78+
showDialog(
79+
context: context,
80+
builder: (BuildContext context) => AboutDialog(
81+
applicationName: GSYStrings.app_name,
82+
applicationVersion: "1.0.0",
83+
applicationIcon: new Image(image: new AssetImage('static/images/logo.png'), width: 50.0, height: 50.0),
84+
applicationLegalese: null,
85+
));
8386
}),
8487
new ListTile(
8588
title: new Text(
8689
GSYStrings.Login_out,
8790
style: GSYConstant.normalText,
8891
),
8992
onTap: () {
93+
UserDao.clearAll(store);
94+
EventDao.clearEvent(store);
9095
NavigatorUtils.goLogin(context);
91-
UserDao.clearAll();
9296
}),
9397
],
9498
),

0 commit comments

Comments
 (0)