diff --git a/lib/RegisterPage.dart b/lib/RegisterPage.dart index 6919bc8..3459bba 100644 --- a/lib/RegisterPage.dart +++ b/lib/RegisterPage.dart @@ -18,6 +18,7 @@ class RegisterPage extends StatefulWidget { } class _RegisterPageState extends State { + late FocusNode _nameFocusNode, _emailFocusNode, _passwordFocusNode, _codeFocusNode; final TextEditingController _nameController = TextEditingController(); final TextEditingController _emailController = TextEditingController(); final TextEditingController _passwordController = TextEditingController(); @@ -33,6 +34,10 @@ class _RegisterPageState extends State { void initState() { super.initState(); _fetchData(); + _nameFocusNode = FocusNode(); + _emailFocusNode = FocusNode(); + _passwordFocusNode = FocusNode(); + _codeFocusNode = FocusNode(); } void _fetchData() async { @@ -124,7 +129,6 @@ class _RegisterPageState extends State { databaseName: 'care', ); await conn.connect(); - try { String name = _nameController.text; String email = _emailController.text; @@ -172,8 +176,13 @@ class _RegisterPageState extends State { @override void dispose() { - _timer?.cancel(); super.dispose(); + _timer?.cancel(); + + _nameFocusNode.dispose(); + _emailFocusNode.dispose(); + _passwordFocusNode.dispose(); + _codeFocusNode.dispose(); } @override @@ -207,6 +216,7 @@ class _RegisterPageState extends State { SizedBox(height: 20), TextField( controller: _nameController, + focusNode: _nameFocusNode, decoration: InputDecoration( border: OutlineInputBorder(), prefixIcon: Icon(Icons.person_outlined), @@ -216,6 +226,7 @@ class _RegisterPageState extends State { SizedBox(height: 20), TextField( controller: _emailController, + focusNode: _emailFocusNode, decoration: InputDecoration( border: OutlineInputBorder(), prefixIcon: Icon(Icons.email_outlined), @@ -226,6 +237,7 @@ class _RegisterPageState extends State { SizedBox(height: 20), TextField( controller: _passwordController, + focusNode: _passwordFocusNode, decoration: InputDecoration( border: OutlineInputBorder(), prefixIcon: Icon(Icons.lock_outlined), @@ -251,6 +263,7 @@ class _RegisterPageState extends State { Expanded( child: TextField( controller: _codeController, + focusNode: _codeFocusNode, decoration: InputDecoration( labelText: '驗證碼', hintText: '填寫驗證碼',