1+ import 'dart:async' ;
2+
13import 'package:flutter/material.dart' ;
4+ import 'package:flutter_redux/flutter_redux.dart' ;
25import 'package:gsy_github_app_flutter/common/config/Config.dart' ;
36import 'package:gsy_github_app_flutter/common/dao/UserDao.dart' ;
47import 'package:gsy_github_app_flutter/common/local/LocalStorage.dart' ;
8+ import 'package:gsy_github_app_flutter/common/redux/GSYState.dart' ;
59import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart' ;
610import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart' ;
711import '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 */
1620class 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}
0 commit comments