Skip to content

Commit 9416e6f

Browse files
committed
优化登录页失败时的提示
1 parent fd14ccd commit 9416e6f

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

CHANGELOG.MD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# 20.3.3
66

77
- 去掉条目详情接口拆分配置
8+
- 优化登录页失败时的提示
89

910
# 20.3.2
1011

lib/user/login.dart

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -159,30 +159,21 @@ class LoginState extends State<LoginView> {
159159
);
160160
}
161161

162-
void login() {
162+
void login() async {
163163
var state = (_formKey.currentState as FormState);
164164
bool result = state.validate();
165165
if (!result) {
166166
Toast.show(context, "服务地址或用户名或密码错误");
167167
return;
168168
}
169169
state.save();
170-
AuthApi()
171-
.login(_baseUrl, _username, _password)
172-
.then((value) => {
173-
Navigator.pushReplacement(context,
174-
MaterialPageRoute(builder: (context) => const MyApp()))
175-
})
176-
.onError((error, stackTrace) => {
177-
FlToast.Fluttertoast.showToast(
178-
msg:
179-
"登录失败 by username: $_username, password: $_password, error: $error",
180-
toastLength: FlToast.Toast.LENGTH_SHORT,
181-
gravity: FlToast.ToastGravity.CENTER,
182-
timeInSecForIosWeb: 5,
183-
backgroundColor: Colors.red,
184-
textColor: Colors.white,
185-
fontSize: 16.0)
186-
});
170+
try {
171+
await AuthApi().login(_baseUrl, _username, _password);
172+
Toast.show(context, "登录成功");
173+
Navigator.pushReplacement(context,
174+
MaterialPageRoute(builder: (context) => const MyApp()));
175+
} catch (e, stackTrace) {
176+
Toast.show(context, "登录失败 by username: $_username, password: $_password, error: $e");
177+
} finally {}
187178
}
188179
}

0 commit comments

Comments
 (0)