Skip to content

Commit 2bc8ff6

Browse files
committed
Login verify
1 parent 73ca2ed commit 2bc8ff6

File tree

8 files changed

+99
-3
lines changed

8 files changed

+99
-3
lines changed

lib/constants/themes.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,19 @@ ThemeData themeBy({
7070
elevatedButtonTheme: ElevatedButtonThemeData(
7171
style: ElevatedButton.styleFrom(
7272
backgroundColor: themeColorDark,
73+
shape: const StadiumBorder(),
7374
),
7475
),
7576
outlinedButtonTheme: OutlinedButtonThemeData(
7677
style: OutlinedButton.styleFrom(
7778
foregroundColor: themeColorDark.withAlpha(200),
79+
shape: const StadiumBorder(),
7880
),
7981
),
8082
textButtonTheme: TextButtonThemeData(
8183
style: TextButton.styleFrom(
8284
foregroundColor: themeColorDark.withAlpha(200),
85+
shape: const StadiumBorder(),
8386
),
8487
),
8588
textSelectionTheme: TextSelectionThemeData(

lib/extensions/string_extension.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
import 'package:flutter/widgets.dart' show Characters;
66

7+
final mobileRegExp = RegExp(r'^1[3-9]\d{9}$');
8+
final emailRegExp = RegExp(
9+
r'^[a-z][0-9a-z\-_ \.]*@([a-z0-9]+\.)+?[a-z]+$',
10+
caseSensitive: false,
11+
);
12+
713
extension StringExtension on String {
814
String get notBreak => Characters(this).join('\u{200B}');
915

@@ -15,6 +21,10 @@ extension StringExtension on String {
1521

1622
String removeFirst(Pattern pattern, [int startIndex = 0]) =>
1723
replaceFirst(pattern, '', startIndex);
24+
25+
bool isMobile() => mobileRegExp.hasMatch(this);
26+
27+
bool isEmail() => emailRegExp.hasMatch(this);
1828
}
1929

2030
extension NullableStringExtension on String? {

lib/l10n/app_en.arb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@
8383
"linkSignUp":"Create an account",
8484
"linkRetrieve":"Fogot password?",
8585

86+
"needUsername": "Please enter a mobile number or email",
87+
"incorectUsername": "Username must be a mobile number or email",
88+
"needPassword": "Please enter your password",
89+
8690
"durationYears": "{many, plural, =1{1 year}other{{many} years}} ago",
8791
"@durationYears": {
8892
"placeholders": {"many": {"type": "int"}}

lib/l10n/app_zh.arb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@
7272
"linkSignUp":"注册新用户",
7373
"linkRetrieve":"找回密码",
7474

75+
"needUsername": "请填写用户名",
76+
"incorectUsername": "请填写手机号码或者邮箱",
77+
"needPassword": "请填写密码",
78+
7579
"durationYears": "{many, plural, =other{{many}年前}}",
7680
"durationMonths": "{many, plural, =other{{many}月前}}",
7781
"durationDays": "{many, plural, =other{{many}天前}}",

lib/l10n/gen/jj_localizations.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,24 @@ abstract class JJLocalizations {
441441
/// **'Fogot password?'**
442442
String get linkRetrieve;
443443

444+
/// No description provided for @needUsername.
445+
///
446+
/// In en, this message translates to:
447+
/// **'Please enter a mobile number or email'**
448+
String get needUsername;
449+
450+
/// No description provided for @incorectUsername.
451+
///
452+
/// In en, this message translates to:
453+
/// **'Username must be a mobile number or email'**
454+
String get incorectUsername;
455+
456+
/// No description provided for @needPassword.
457+
///
458+
/// In en, this message translates to:
459+
/// **'Please enter your password'**
460+
String get needPassword;
461+
444462
/// No description provided for @durationYears.
445463
///
446464
/// In en, this message translates to:

lib/l10n/gen/jj_localizations_en.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,15 @@ class JJLocalizationsEn extends JJLocalizations {
190190
@override
191191
String get linkRetrieve => 'Fogot password?';
192192

193+
@override
194+
String get needUsername => 'Please enter a mobile number or email';
195+
196+
@override
197+
String get incorectUsername => 'Username must be a mobile number or email';
198+
199+
@override
200+
String get needPassword => 'Please enter your password';
201+
193202
@override
194203
String durationYears(num many) {
195204
final String pluralString = intl.Intl.pluralLogic(

lib/l10n/gen/jj_localizations_zh.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,15 @@ class JJLocalizationsZh extends JJLocalizations {
190190
@override
191191
String get linkRetrieve => '找回密码';
192192

193+
@override
194+
String get needUsername => '请填写用户名';
195+
196+
@override
197+
String get incorectUsername => '请填写手机号码或者邮箱';
198+
199+
@override
200+
String get needPassword => '请填写密码';
201+
193202
@override
194203
String durationYears(num many) {
195204
return intl.Intl.pluralLogic(

lib/pages/login/login.dart

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,27 @@ class LoginPage extends StatefulWidget {
1111
}
1212

1313
class _LoginPageState extends State<LoginPage> {
14+
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
15+
16+
String? _username;
17+
String? _password;
18+
1419
@override
1520
void initState() {
1621
super.initState();
1722
}
1823

24+
Future<void> _doLogin() async {
25+
if (_formKey.currentState!.validate()) {
26+
final result = await PassportAPI.login(_username!, _password!);
27+
if (result.isSucceed) {
28+
print(result);
29+
} else {
30+
showToast(result.msg);
31+
}
32+
}
33+
}
34+
1935
@override
2036
Widget build(BuildContext context) {
2137
return Scaffold(
@@ -32,6 +48,8 @@ class _LoginPageState extends State<LoginPage> {
3248
borderRadius: BorderRadius.circular(8),
3349
),
3450
child: Form(
51+
key: _formKey,
52+
autovalidateMode: AutovalidateMode.onUserInteraction,
3553
child: Column(
3654
children: [
3755
SizedBox(
@@ -63,6 +81,16 @@ class _LoginPageState extends State<LoginPage> {
6381
),
6482
const Gap.v(16),
6583
TextFormField(
84+
validator: (v) {
85+
if (v == null || v.isEmpty) {
86+
return context.l10n.needUsername;
87+
}
88+
if (!v.isMobile() && !v.isEmail()) {
89+
return context.l10n.incorectUsername;
90+
}
91+
return null;
92+
},
93+
onChanged: (v) => _username = v,
6694
keyboardType: TextInputType.emailAddress,
6795
decoration: InputDecoration(
6896
hintText: context.l10n.hintUsername,
@@ -75,6 +103,13 @@ class _LoginPageState extends State<LoginPage> {
75103
TextFormField(
76104
obscureText: true,
77105
obscuringCharacter: '*',
106+
validator: (v) {
107+
if (v?.isEmpty ?? true) {
108+
return context.l10n.needPassword;
109+
}
110+
return null;
111+
},
112+
onChanged: (v) => _password = v,
78113
keyboardType: TextInputType.visiblePassword,
79114
decoration: InputDecoration(
80115
hintText: context.l10n.hintPassword,
@@ -83,7 +118,7 @@ class _LoginPageState extends State<LoginPage> {
83118
),
84119
const Gap.v(8),
85120
ElevatedButton(
86-
onPressed: () {},
121+
onPressed: _doLogin,
87122
child: Center(
88123
child: Text(context.l10n.buttonSignIn),
89124
),
@@ -92,12 +127,16 @@ class _LoginPageState extends State<LoginPage> {
92127
Row(
93128
children: [
94129
TextButton(
95-
onPressed: () {},
130+
onPressed: () {
131+
showToast('Comming soon');
132+
},
96133
child: Text(context.l10n.linkSignUp),
97134
),
98135
const Spacer(),
99136
TextButton(
100-
onPressed: () {},
137+
onPressed: () {
138+
showToast('Comming soon');
139+
},
101140
child: Text(context.l10n.linkRetrieve),
102141
),
103142
],

0 commit comments

Comments
 (0)