X Tutup
Skip to content

Commit f120da9

Browse files
committed
add router uitls
1 parent 6bfe46b commit f120da9

File tree

11 files changed

+124
-48
lines changed

11 files changed

+124
-48
lines changed

android/gradlew

100644100755
File mode changed.

ios/Flutter/Debug.xcconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
12
#include "Generated.xcconfig"

ios/Flutter/Release.xcconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
12
#include "Generated.xcconfig"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:gsy_github_app_flutter/page/HomePage.dart';
3+
import 'package:gsy_github_app_flutter/page/LoginPage.dart';
4+
5+
class NavigatorUtils {
6+
static pushReplacementNamed(BuildContext context, String routeName) {
7+
Navigator.pushReplacementNamed(context, routeName);
8+
}
9+
10+
static pushNamed(BuildContext context, String routeName) {
11+
Navigator.pushNamed(context, routeName);
12+
}
13+
14+
static goHome(BuildContext context) {
15+
Navigator.pushReplacementNamed(context, HomePage.sName);
16+
}
17+
18+
static goLogin(BuildContext context) {
19+
Navigator.pushReplacementNamed(context, LoginPage.sName);
20+
}
21+
}

lib/main.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ import 'package:gsy_github_app_flutter/page/WelcomePage.dart';
88
import 'package:flutter_redux/flutter_redux.dart';
99
import 'package:redux/redux.dart';
1010

11-
1211
void main() {
1312
runApp(new FlutterReduxApp());
1413
}
1514

1615
class FlutterReduxApp extends StatelessWidget {
17-
18-
final store = new Store<GSYState>(appReducer, initialState: new GSYState(userInfo: User.empty()));
16+
final store = new Store<GSYState>(appReducer,
17+
initialState: new GSYState(userInfo: User.empty()));
1918

2019
FlutterReduxApp({Key key}) : super(key: key);
2120

@@ -29,13 +28,13 @@ class FlutterReduxApp extends StatelessWidget {
2928
primarySwatch: GSYColors.primarySwatch,
3029
),
3130
routes: {
32-
"/": (context) {
31+
WelcomePage.sName: (context) {
3332
return WelcomePage();
3433
},
35-
"home": (context) {
34+
HomePage.sName: (context) {
3635
return HomePage();
3736
},
38-
"login": (context) {
37+
LoginPage.sName: (context) {
3938
return LoginPage();
4039
},
4140
}),

lib/page/DynamicPage.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
import 'dart:async';
3+
4+
import 'package:flutter/material.dart';
5+
import 'package:flutter_redux/flutter_redux.dart';
6+
import 'package:gsy_github_app_flutter/common/model/User.dart';
7+
import 'package:gsy_github_app_flutter/common/redux/GSYState.dart';
8+
import 'package:gsy_github_app_flutter/common/redux/UserRedux.dart';
9+
10+
class DynamicPage extends StatelessWidget {
11+
12+
@override
13+
Widget build(BuildContext context) {
14+
return new StoreBuilder<GSYState>(
15+
builder: (context, store) {
16+
new Future.delayed(const Duration(seconds: 2), () {
17+
User user = store.state.userInfo;
18+
user.login = "new login";
19+
user.name = "new name";
20+
store.dispatch(new UpdateUserAction(user));
21+
});
22+
return new Text(
23+
store.state.userInfo.login,
24+
style: Theme.of(context).textTheme.display1,
25+
);;
26+
},
27+
);
28+
}
29+
}

lib/page/HomePage.dart

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
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';
82
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
3+
import 'package:gsy_github_app_flutter/page/DynamicPage.dart';
4+
import 'package:gsy_github_app_flutter/page/MyPage.dart';
5+
import 'package:gsy_github_app_flutter/page/TrendPage.dart';
96
import 'package:gsy_github_app_flutter/widget/GSYTabBarWidget.dart';
107

118
class HomePage extends StatelessWidget {
9+
10+
static final String sName = "home";
11+
1212
// This widget is the root of your application.
1313
@override
1414
Widget build(BuildContext context) {
@@ -20,30 +20,9 @@ class HomePage extends StatelessWidget {
2020
new Tab(icon: new Icon(Icons.directions_bike)),
2121
],
2222
tabViews: [
23-
new StoreBuilder<GSYState>(
24-
builder: (context, store) {
25-
new Future.delayed(const Duration(seconds: 2), () {
26-
User user = store.state.userInfo;
27-
user.login = "new login";
28-
user.name = "new name";
29-
store.dispatch(new UpdateUserAction(user));
30-
});
31-
return new Text(
32-
store.state.userInfo.login,
33-
style: Theme.of(context).textTheme.display1,
34-
);;
35-
},
36-
),
37-
new StoreConnector<GSYState, String>(
38-
converter: (store) => store.state.userInfo.name,
39-
builder: (context, count) {
40-
return new Text(
41-
count,
42-
style: Theme.of(context).textTheme.display1,
43-
);
44-
},
45-
),
46-
new Icon(Icons.directions_bike),
23+
new DynamicPage(),
24+
new TrendPage(),
25+
new MyPage(),
4726
],
4827
backgroundColor: GSYColors.primarySwatch,
4928
indicatorColor: Colors.white,

lib/page/LoginPage.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import 'package:flutter/material.dart';
2-
import 'package:fluttertoast/fluttertoast.dart';
32
import 'package:gsy_github_app_flutter/common/config/Config.dart';
43
import 'package:gsy_github_app_flutter/common/dao/UserDao.dart';
54
import 'package:gsy_github_app_flutter/common/local/LocalStorage.dart';
65
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
6+
import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart';
77
import 'package:gsy_github_app_flutter/widget/GSYFlexButton.dart';
88
import 'package:gsy_github_app_flutter/widget/GSYInputWidget.dart';
99

1010
class LoginPage extends StatefulWidget {
11+
12+
static final String sName = "login";
13+
1114
@override
1215
State createState() {
1316
return new _LoginPageState();
@@ -33,8 +36,12 @@ class _LoginPageState extends State<LoginPage> {
3336
initParams() async {
3437
_userName = await LocalStorage.get(Config.USER_NAME_KEY);
3538
_password = await LocalStorage.get(Config.PW_KEY);
36-
userController.value = new TextEditingValue(text: _userName);
37-
pwController.value = new TextEditingValue(text: _password);
39+
if(_userName != null) {
40+
userController.value = new TextEditingValue(text: _userName);
41+
}
42+
if(_password != null) {
43+
pwController.value = new TextEditingValue(text: _password);
44+
}
3845
}
3946

4047
@override
@@ -87,7 +94,8 @@ class _LoginPageState extends State<LoginPage> {
8794
}
8895
UserDao.login(_userName, _password, (data) {
8996
if (data != null && data.result == true) {
90-
Fluttertoast.showToast(msg: GSYStrings.login_success);
97+
NavigatorUtils.goHome(context);
98+
//Fluttertoast.showToast(msg: GSYStrings.login_success);
9199
}
92100
});
93101
},

lib/page/MyPage.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
import 'package:flutter/material.dart';
3+
import 'package:flutter_redux/flutter_redux.dart';
4+
import 'package:gsy_github_app_flutter/common/redux/GSYState.dart';
5+
6+
class MyPage extends StatelessWidget {
7+
@override
8+
Widget build(BuildContext context) {
9+
return new StoreConnector<GSYState, String>(
10+
converter: (store) => store.state.userInfo.name,
11+
builder: (context, count) {
12+
return new Text(
13+
count,
14+
style: Theme.of(context).textTheme.display1,
15+
);
16+
},
17+
);
18+
}
19+
}

lib/page/TrendPage.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
import 'package:flutter/material.dart';
3+
import 'package:flutter_redux/flutter_redux.dart';
4+
import 'package:gsy_github_app_flutter/common/redux/GSYState.dart';
5+
6+
class TrendPage extends StatelessWidget {
7+
@override
8+
Widget build(BuildContext context) {
9+
return new StoreConnector<GSYState, String>(
10+
converter: (store) => store.state.userInfo.name,
11+
builder: (context, count) {
12+
return new Text(
13+
count,
14+
style: Theme.of(context).textTheme.display1,
15+
);
16+
},
17+
);
18+
}
19+
}

0 commit comments

Comments
 (0)
X Tutup