11import 'package:flutter/material.dart' ;
2+ import 'package:gsy_github_app_flutter/common/config/Config.dart' ;
3+ import 'package:gsy_github_app_flutter/common/dao/UserDao.dart' ;
4+ import 'package:gsy_github_app_flutter/common/local/LocalStorage.dart' ;
25import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart' ;
36import 'package:gsy_github_app_flutter/widget/GSYFlexButton.dart' ;
47import 'package:gsy_github_app_flutter/widget/GSYInputWidget.dart' ;
58
6- class LoginPage extends StatelessWidget {
9+ class LoginPage extends StatefulWidget {
10+ @override
11+ State createState () {
12+ return new _LoginPageState ();
13+ }
14+ }
15+
16+ class _LoginPageState extends State <LoginPage > {
17+ var _userName = "" ;
18+
19+ var _password = "" ;
20+
21+ final TextEditingController userController = new TextEditingController ();
22+ final TextEditingController pwController = new TextEditingController ();
23+
24+ _LoginPageState () : super ();
25+
26+ @override
27+ void initState () {
28+ super .initState ();
29+ initParams ();
30+ }
31+
32+ initParams () async {
33+ _userName = await LocalStorage .get (Config .USER_NAME_KEY );
34+ _password = await LocalStorage .get (Config .PW_KEY );
35+ userController.value = new TextEditingValue (text: _userName);
36+ pwController.value = new TextEditingValue (text: _password);
37+ }
38+
739 @override
840 Widget build (BuildContext context) {
941 return new Container (
@@ -22,15 +54,38 @@ class LoginPage extends StatelessWidget {
2254 children: < Widget > [
2355 new Image (image: new AssetImage ('static/images/logo.png' ), width: 90.0 , height: 90.0 ),
2456 new Padding (padding: new EdgeInsets .all (10.0 )),
25- new GSYInputWidget (hintText: "11111" , iconData: Icons .access_alarm),
57+ new GSYInputWidget (
58+ hintText: GSYStrings .login_username_hint_text,
59+ iconData: Icons .access_alarm,
60+ onChanged: (String value) {
61+ _userName = value;
62+ },
63+ controller: userController,
64+ ),
2665 new Padding (padding: new EdgeInsets .all (10.0 )),
27- new GSYInputWidget (hintText: "11111" , iconData: Icons .access_alarm),
66+ new GSYInputWidget (
67+ hintText: GSYStrings .login_password_hint_text,
68+ iconData: Icons .access_alarm,
69+ onChanged: (String value) {
70+ print (value);
71+ _password = value;
72+ },
73+ controller: pwController,
74+ ),
2875 new Padding (padding: new EdgeInsets .all (30.0 )),
2976 new GSYFlexButton (
3077 text: GSYStrings .login_text,
3178 color: Color (GSYColors .primaryValue),
3279 textColor: Color (GSYColors .textWhite),
33- onPress: () {},
80+ onPress: () {
81+ if (_userName == null || _userName.length == 0 ) {
82+ return ;
83+ }
84+ if (_password == null || _password.length == 0 ) {
85+ return ;
86+ }
87+ UserDao .login (_userName, _password, (data) {});
88+ },
3489 )
3590 ],
3691 ),
0 commit comments