11import 'package:flutter/material.dart' ;
2+ import 'dart:math' as math;
23import 'package:efox_flutter/lang/index.dart' show AppLocalizations;
34import 'package:efox_flutter/store/index.dart' show Store, UserModel;
45
@@ -14,116 +15,190 @@ class _IndexState extends State<Index> {
1415 TextEditingController pwdCtl = TextEditingController (text: '' );
1516
1617 GlobalKey _formKey = GlobalKey <FormState >();
18+ OverlayState _overlayState;
19+ OverlayEntry _overlayEntry;
20+
21+ /**
22+ * 弹窗内容
23+ */
24+ renderOverlay (String text) {
25+ _overlayEntry? .remove ();
26+ _overlayState = Overlay .of (context);
27+ _overlayEntry = OverlayEntry (builder: (context) {
28+ return Center (child: Text (text));
29+ });
30+ _overlayState.insert (_overlayEntry);
31+ }
32+
33+ /**
34+ * 顶部图标
35+ */
36+ renderGithubImage () {
37+ return Row (
38+ mainAxisAlignment: MainAxisAlignment .center,
39+ children: < Widget > [
40+ Image .asset (
41+ 'assets/imgs/github_2.png' ,
42+ width: 50 ,
43+ height: 50 ,
44+ ),
45+ SizedBox (
46+ width: 10 ,
47+ ),
48+ Transform .rotate (
49+ child: Icon (
50+ Icons .import_export,
51+ color: Colors .black,
52+ ),
53+ angle: math.pi / 2 ,
54+ ),
55+ SizedBox (
56+ width: 10 ,
57+ ),
58+ Image .asset (
59+ 'assets/imgs/github_1.png' ,
60+ width: 50 ,
61+ height: 50 ,
62+ ),
63+ ],
64+ );
65+ }
66+
1767 @override
1868 Widget build (BuildContext ctx) {
19- return Scaffold (
20- appBar: AppBar (
21- centerTitle: true ,
22- title: Text (
23- AppLocalizations .$t ('common.login' ),
24- textAlign: TextAlign .center,
69+ return WillPopScope (
70+ child: Scaffold (
71+ appBar: AppBar (
72+ centerTitle: true ,
73+ title: Text (
74+ AppLocalizations .$t ('common.login' ),
75+ textAlign: TextAlign .center,
76+ ),
77+ automaticallyImplyLeading: false ,
2578 ),
26- automaticallyImplyLeading: false ,
27- ),
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: AppLocalizations .$t ('login.account' ),
43- hintText: AppLocalizations .$t ('login.account_tips' ),
44- icon: Icon (Icons .person),
79+ body: Builder (builder: (BuildContext context) {
80+ return SingleChildScrollView (
81+ child: Padding (
82+ padding: EdgeInsets .symmetric (vertical: 50 , horizontal: 24 ),
83+ child: Form (
84+ key: _formKey,
85+ autovalidate: true ,
86+ child: Column (
87+ children: < Widget > [
88+ renderGithubImage (),
89+ TextFormField (
90+ controller: nameCtl,
91+ autofocus: true ,
92+ decoration: InputDecoration (
93+ labelText: AppLocalizations .$t ('login.account' ),
94+ hintText: AppLocalizations .$t ('login.account_tips' ),
95+ icon: Icon (Icons .person),
96+ ),
97+ validator: (v) {
98+ return v.trim ().length > 0
99+ ? null
100+ : AppLocalizations .$t ('login.account_error_tips' );
101+ },
102+ ),
103+ TextFormField (
104+ controller: pwdCtl,
105+ decoration: InputDecoration (
106+ labelText: AppLocalizations .$t ('login.password' ),
107+ hintText: AppLocalizations .$t ('login.password_tips' ),
108+ icon: Icon (Icons .lock),
109+ ),
110+ obscureText: true ,
111+ validator: (v) {
112+ return v.trim ().length > 0
113+ ? null
114+ : AppLocalizations .$t ('login.password_error_tips' );
115+ },
116+ ),
117+ Padding (
118+ padding: EdgeInsets .only (top: 50 ),
119+ child: Row (
120+ children: < Widget > [
121+ Expanded (
122+ child: RaisedButton (
123+ padding: EdgeInsets .all (15 ),
124+ color: Theme .of (context).primaryColor,
125+ textColor: Theme .of (context)
126+ .primaryTextTheme
127+ .title
128+ .color,
129+ child: Text (
130+ AppLocalizations .$t ('common.login' ),
131+ ),
132+ onPressed: () async {
133+ if ((_formKey.currentState as FormState )
134+ .validate ()) {
135+ await Store .value <UserModel >(context)
136+ .$loginController (context, {
137+ 'name' : nameCtl.text,
138+ 'pwd' : pwdCtl.text
139+ });
140+ }
141+ },
142+ ),
143+ )
144+ ],
145+ ),
45146 ),
46- validator: (v) {
47- return v.trim ().length > 0 ? null : AppLocalizations .$t ('login.account_error_tips' );
48- },
49- ),
50- TextFormField (
51- controller: pwdCtl,
52- decoration: InputDecoration (
53- labelText: AppLocalizations .$t ('login.password' ),
54- hintText: AppLocalizations .$t ('login.password_tips' ),
55- icon: Icon (Icons .lock),
147+ SizedBox (
148+ height: 10 ,
56149 ),
57- obscureText: true ,
58- validator: (v) {
59- return v.trim ().length > 0 ? null : AppLocalizations .$t ('login.password_error_tips' );
60- },
61- ),
62- Padding (
63- padding: EdgeInsets .only (top: 50 ),
64- child: Row (
150+ Row (
151+ mainAxisAlignment: MainAxisAlignment .center,
65152 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' ),
153+ GestureDetector (
154+ child: Text (
155+ 'Github账户登录说明' ,
156+ style: TextStyle (
157+ decoration: TextDecoration .underline,
158+ textBaseline: TextBaseline .ideographic,
159+ decorationColor: Color (0xff000000 ),
74160 ),
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- },
85- ),
86- )
87- ],
88- ),
89- ),
90- SizedBox (
91- height: 10 ,
92- ),
93- Row (
94- mainAxisAlignment: MainAxisAlignment .center,
95- children: < Widget > [
96- GestureDetector (
97- child: Text (
98- 'Github账户登录说明' ,
99- style: TextStyle (
100- decoration: TextDecoration .underline,
101- textBaseline: TextBaseline .ideographic,
102- decorationColor: Color (0xff000000 ),
103161 ),
162+ onTap: () {
163+ renderOverlay (" Text 1" );
164+ },
104165 ),
105- ),
106- SizedBox (
107- width : 10 ,
108- ),
109- GestureDetector (
110- child : Text (
111- '软件许可及服务协议' ,
112- style : TextStyle (
113- decoration : TextDecoration .underline ,
114- textBaseline : TextBaseline .ideographic ,
115- decorationColor : const Color ( 0xff000000 ),
166+ SizedBox (
167+ width : 10 ,
168+ ) ,
169+ GestureDetector (
170+ child : Text (
171+ '软件许可及服务协议' ,
172+ style : TextStyle (
173+ decoration : TextDecoration .underline,
174+ textBaseline : TextBaseline .ideographic ,
175+ decorationColor : const Color ( 0xff000000 ) ,
176+ ),
116177 ),
178+ onTap: () {
179+ renderOverlay (" Text 2" );
180+ },
117181 ),
118- ) ,
119- ],
120- )
121- ] ,
182+ ] ,
183+ )
184+ ],
185+ ) ,
122186 ),
123187 ),
124- ),
125- );
126- }),
188+ );
189+ }),
190+ ),
191+ onWillPop: () {
192+ beforeDispose ();
193+ },
127194 );
128195 }
196+ beforeDispose () {
197+ if (_overlayEntry != null ) {
198+ _overlayEntry.remove ();
199+ _overlayEntry = null ;
200+ } else {
201+ Navigator .of (context).pop ();
202+ }
203+ }
129204}
0 commit comments