feat: 新增基礎驗證、錯誤處理
1. 為註冊資料新增基礎驗證及驗證碼驗證實作 2. 錯誤欄位游標自動移到該欄
This commit is contained in:
@@ -111,6 +111,7 @@ class _RegisterPageState extends State<RegisterPage> {
|
|||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(content: Text('請輸入正確的電子信箱')),
|
SnackBar(content: Text('請輸入正確的電子信箱')),
|
||||||
);
|
);
|
||||||
|
_emailFocusNode.requestFocus();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,6 +120,46 @@ class _RegisterPageState extends State<RegisterPage> {
|
|||||||
_startTimer();
|
_startTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool _isDataCorrect() {
|
||||||
|
String name = _nameController.text;
|
||||||
|
String email = _emailController.text;
|
||||||
|
String password = _passwordController.text;
|
||||||
|
String code = _codeController.text;
|
||||||
|
|
||||||
|
if (name == ''){
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text('用戶姓名不可為空')),
|
||||||
|
);
|
||||||
|
_nameFocusNode.requestFocus();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (email == ''){
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text('電子信箱不可為空')),
|
||||||
|
);
|
||||||
|
_emailFocusNode.requestFocus();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (password== ''){
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text('密碼不可為空')),
|
||||||
|
);
|
||||||
|
_passwordFocusNode.requestFocus();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (code != _generatedCode){
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text('驗證碼錯誤')),
|
||||||
|
);
|
||||||
|
_codeFocusNode.requestFocus();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void registerBtn() async {
|
void registerBtn() async {
|
||||||
if (!_isDataCorrect()) return;
|
if (!_isDataCorrect()) return;
|
||||||
final conn = await MySQLConnection.createConnection(
|
final conn = await MySQLConnection.createConnection(
|
||||||
|
|||||||
Reference in New Issue
Block a user