File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,8 +8,8 @@ import 'package:gsy_github_app_flutter/common/local/LocalStorage.dart';
88import 'package:gsy_github_app_flutter/common/model/User.dart' ;
99import 'package:gsy_github_app_flutter/common/net/Address.dart' ;
1010import 'package:gsy_github_app_flutter/common/net/Api.dart' ;
11+ import 'package:gsy_github_app_flutter/common/redux/UserRedux.dart' ;
1112import 'package:redux/redux.dart' ;
12- import 'package:gsy_github_app_flutter/common/redux/GSYState.dart' ;
1313
1414class UserDao {
1515 static login (userName, password, callback) async {
@@ -50,7 +50,7 @@ class UserDao {
5050 var token = await LocalStorage .get (Config .TOKEN_KEY );
5151 var res = await getUserInfoLocal ();
5252 if (res != null && res.result && token != null ) {
53- store.dispatch (UserActions (res.data));
53+ store.dispatch (UpdateUserAction (res.data));
5454 }
5555 return new DataResult (res.data, (res.result && (token != null )));
5656 }
Original file line number Diff line number Diff line change 11import 'package:gsy_github_app_flutter/common/model/User.dart' ;
2+ import 'package:gsy_github_app_flutter/common/redux/UserRedux.dart' ;
23
34class GSYState {
5+
46 User userInfo;
7+
58 GSYState ({this .userInfo});
6- }
79
8- // One simple action: Increment
9- class UserActions {
10- final User userInfo;
11- UserActions (this .userInfo);
1210}
1311
14- GSYState counterReducer ( GSYState state, dynamic action) {
15- if (action is UserActions ) {
16- state.userInfo = action.userInfo;
17- }
18- return state ;
12+
13+ GSYState appReducer ( GSYState state, action ) {
14+ return GSYState (
15+ userInfo : UserReducer (state.userInfo, action),
16+ ) ;
1917}
2018
Original file line number Diff line number Diff line change 1+
2+ import 'package:gsy_github_app_flutter/common/model/User.dart' ;
3+ import 'package:redux/redux.dart' ;
4+
5+ final UserReducer = combineReducers <User >([
6+ TypedReducer <User , UpdateUserAction >(_updateLoaded),
7+ ]);
8+
9+ User _updateLoaded (User user, action) {
10+ user = action.userInfo;
11+ return user;
12+ }
13+
14+ class UpdateUserAction {
15+ final User userInfo;
16+ UpdateUserAction (this .userInfo);
17+ }
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ void main() {
1515
1616class FlutterReduxApp extends StatelessWidget {
1717
18- final store = new Store <GSYState >(counterReducer , initialState: new GSYState (userInfo: User .empty ()));
18+ final store = new Store <GSYState >(appReducer , initialState: new GSYState (userInfo: User .empty ()));
1919
2020 FlutterReduxApp ({Key key}) : super (key: key);
2121
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
44import 'package:flutter_redux/flutter_redux.dart' ;
55import 'package:gsy_github_app_flutter/common/model/User.dart' ;
66import 'package:gsy_github_app_flutter/common/redux/GSYState.dart' ;
7+ import 'package:gsy_github_app_flutter/common/redux/UserRedux.dart' ;
78import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart' ;
89import 'package:gsy_github_app_flutter/widget/GSYTabBarWidget.dart' ;
910
@@ -23,9 +24,9 @@ class HomePage extends StatelessWidget {
2324 builder: (context, store) {
2425 new Future .delayed (const Duration (seconds: 2 ), () {
2526 User user = store.state.userInfo;
26- user.login = "ffff " ;
27- user.name = "ttttt " ;
28- store.dispatch (new UserActions (user));
27+ user.login = "new login " ;
28+ user.name = "new name " ;
29+ store.dispatch (new UpdateUserAction (user));
2930 });
3031 return new Text (
3132 store.state.userInfo.login,
You can’t perform that action at this time.
0 commit comments