11import 'package:flutter/material.dart' ;
22import 'package:efox_flutter/lang/index.dart' show AppLocalizations;
33import 'package:efox_flutter/store/index.dart' show Store, UserModel;
4- class Index extends StatefulWidget {
54
5+ class Index extends StatefulWidget {
66 Index ({Key key}) : super (key: key);
77
88 @override
@@ -15,7 +15,7 @@ class _IndexState extends State<Index> {
1515
1616 GlobalKey _formKey = GlobalKey <FormState >();
1717 @override
18- Widget build (BuildContext context ) {
18+ Widget build (BuildContext ctx ) {
1919 return Scaffold (
2020 appBar: AppBar (
2121 centerTitle: true ,
@@ -25,70 +25,74 @@ class _IndexState extends State<Index> {
2525 ),
2626 automaticallyImplyLeading: false ,
2727 ),
28- body: SingleChildScrollView (
29- child: Padding (
30- padding: EdgeInsets .symmetric (vertical: 50 , horizontal: 24 ),
31- child: Form (
32- key: _formKey,
33- autovalidate: true ,
34- child: Column (
35- children: < Widget > [
36- TextFormField (
37- controller: nameCtl,
38- autofocus: true ,
39- decoration: InputDecoration (
40- labelText: '账户名' ,
41- hintText: '请输入Github账户名' ,
42- icon: Icon (Icons .person),
28+ body: Builder (builder: (BuildContext context) {
29+ // Store.setWidgetCtx(context);
30+ return SingleChildScrollView (
31+ child: Padding (
32+ padding: EdgeInsets .symmetric (vertical: 50 , horizontal: 24 ),
33+ child: Form (
34+ key: _formKey,
35+ autovalidate: true ,
36+ child: Column (
37+ children: < Widget > [
38+ TextFormField (
39+ controller: nameCtl,
40+ autofocus: true ,
41+ decoration: InputDecoration (
42+ labelText: '账户名' ,
43+ hintText: '请输入Github账户名' ,
44+ icon: Icon (Icons .person),
45+ ),
46+ validator: (v) {
47+ return v.trim ().length > 0 ? null : '用户名不能为空' ;
48+ },
4349 ),
44- validator: (v) {
45- return v.trim ().length > 0 ? null : '用户名不能为空' ;
46- },
47- ),
48- TextFormField (
49- controller: pwdCtl,
50- decoration: InputDecoration (
51- labelText: '密码' ,
52- hintText: '请输入登录密码' ,
53- icon: Icon (Icons .lock),
50+ TextFormField (
51+ controller: pwdCtl,
52+ decoration: InputDecoration (
53+ labelText: '密码' ,
54+ hintText: '请输入登录密码' ,
55+ icon: Icon (Icons .lock),
56+ ),
57+ obscureText: true ,
58+ validator: (v) {
59+ return v.trim ().length > 5 ? null : "密码不能少于6位" ;
60+ },
5461 ),
55- obscureText: true ,
56- validator: (v) {
57- return v.trim ().length > 5 ? null : "密码不能少于6位" ;
58- },
59- ),
60- Padding (
61- padding: EdgeInsets .only (top: 50 ),
62- child: Row (
63- children: < Widget > [
64- Expanded (
65- child: RaisedButton (
66- padding: EdgeInsets .all (15 ),
67- color: Theme .of (context).primaryColor,
68- textColor:
69- Theme .of (context).primaryTextTheme.title.color,
70- child: Text (
71- AppLocalizations .$t ('common.login' ),
62+ Padding (
63+ padding: EdgeInsets .only (top: 50 ),
64+ child: Row (
65+ children: < Widget > [
66+ Expanded (
67+ child: RaisedButton (
68+ padding: EdgeInsets .all (15 ),
69+ color: Theme .of (context).primaryColor,
70+ textColor:
71+ Theme .of (context).primaryTextTheme.title.color,
72+ child: Text (
73+ AppLocalizations .$t ('common.login' ),
74+ ),
75+ onPressed: () async {
76+ if ((_formKey.currentState as FormState )
77+ .validate ()) {
78+ Store .value <UserModel >(context)
79+ .$loginController (context, {
80+ 'name' : nameCtl.text,
81+ 'pwd' : pwdCtl.text
82+ });
83+ }
84+ },
7285 ),
73- onPressed: () {
74- if ((_formKey.currentState as FormState )
75- .validate ()) {
76- Store .value <UserModel >(context).$login ({
77- 'name' : nameCtl.text,
78- 'pwd' : pwdCtl.text
79- });
80- }
81- },
82- ),
83- )
84- ],
85- ),
86- )
87- ],
86+ )
87+ ],
88+ ),
89+ )
90+ ],
91+ ),
8892 ),
8993 ),
90- ),
91- ),
94+ );
95+ } ),
9296 );
9397 }
9498}
0 commit comments