SignInPage.dart
9.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import './DashBoard.dart';
class SignInPage extends StatefulWidget {
@override
_SignInPageState createState() => _SignInPageState();
}
///
class _SignInPageState extends State<SignInPage> {
bool passwordVisible = false;
bool _validateEmail = false;
bool _validatePassword = false;
final emailController = TextEditingController();
final passwordController = TextEditingController();
Widget build(BuildContext context) {
final Size size = MediaQuery.of(context).size;
final mqData = MediaQuery.of(context);
final mqDataScale = mqData.copyWith(textScaleFactor: 1.0);
return WillPopScope(
onWillPop: () {
if (Navigator.canPop(context)) {
//Navigator.pop(context);
Navigator.of(context).pop();
} else {
SystemNavigator.pop();
}
},
child: Scaffold(
body: Builder(
builder: (BuildContext context) {
return ListView(
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 25, left: 18, right: 18),
child: Stack(
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(20, 0, 0, 0),
child: Text('로그인',
textScaleFactor: 1.0,
style: TextStyle(
fontSize: 34,
fontFamily: 'Noto',
fontWeight: FontWeight.bold)),
),
Padding(
padding: const EdgeInsets.fromLTRB(20, 0, 20, 0),
child: new Column(
children: <Widget>[
MediaQuery(
data: mqDataScale,
child: TextFormField(
keyboardType: TextInputType.text,
controller: emailController,
decoration: InputDecoration(
labelText: '이메일',
helperText: '이메일 주소를 입력해주세요.',
contentPadding:
EdgeInsets.fromLTRB(0, 5, 0, 5),
errorText: _validateEmail
? '등록되지 않은 아이디입니다.'
: null,
labelStyle: TextStyle(
fontSize: 14,
color: Color(0xff000000)),
helperStyle: TextStyle(
fontSize: 12,
color: Color(0xffb2b2b2)),
// Here is key idea
),
),
)
],
),
),
Padding(
padding: const EdgeInsets.fromLTRB(20, 0, 20, 20),
child: new Column(
children: <Widget>[
MediaQuery(
data: mqDataScale,
child: TextFormField(
keyboardType: TextInputType.text,
controller: passwordController,
obscureText:
!passwordVisible, //This will obscure text dynamically
decoration: InputDecoration(
labelText: '비밀번호',
helperText: '비밀번호를 입력해 주세요.',
errorText: _validatePassword
? '비밀번호가 일치하지 않습니다.'
: null,
labelStyle: TextStyle(
fontSize: 14,
color: Color(0xff000000)),
helperStyle: TextStyle(
fontSize: 12,
color: Color(0xffb2b2b2)),
// Here is key idea
suffixIcon: IconButton(
icon: Icon(
// Based on passwordVisible state choose the icon
passwordVisible
? Icons.visibility
: Icons.visibility_off,
color: Color(0xff2c2c2c),
),
onPressed: () {
// Update the state i.e. toogle the state of passwordVisible variable
setState(() {
passwordVisible = !passwordVisible;
});
},
),
),
),
)
],
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: size.width * 0.8,
height: 46,
child: RaisedButton(
color: Color(0xff1674f6),
child: Text("로그인",
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontFamily: 'Noto',
fontWeight: FontWeight.bold)),
onPressed: () async {
String saveMessage;
if (emailController.text.isEmpty ||
passwordController.text.isEmpty) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: new Text('이메일 & 비밀번호'),
content: new Text(
'이메일과 비밀번호를 입력해주세요.'),
actions: <Widget>[
new FlatButton(
child: new Text('Close'),
onPressed: () {
Navigator.of(context)
.pop();
})
],
);
});
} else {
emailController.text =
emailController.text.trim();
passwordController.text =
passwordController.text.trim();
saveMessage = "로그인 성공";
if (saveMessage == "로그인 성공") {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) =>
DashBoard(pageNumber: 1),
));
}
}
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
),
),
],
),
],
),
],
),
),
],
);
},
),
),
);
}
}