From 4be851ab867ab6b6873d89e9c7de79747209b74f Mon Sep 17 00:00:00 2001 From: kuei <110316104@gms.tcu.edu.tw> Date: Thu, 12 Sep 2024 20:36:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=80=8B=E4=BA=BA=E8=B3=87=E6=96=99=E5=8A=A0?= =?UTF-8?q?=E5=85=A5username?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/PersonalInfo.dart | 49 ++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/lib/PersonalInfo.dart b/lib/PersonalInfo.dart index 68ab643..7d31487 100644 --- a/lib/PersonalInfo.dart +++ b/lib/PersonalInfo.dart @@ -14,12 +14,12 @@ class PersonalInfo extends StatefulWidget { } class _PersonalInfoState extends State { - String _name = '', _phone = '', _gender = '', _address = '', _email = '', _password = ''; + String _username='',_realname = '', _phone = '', _gender = '', _address = '', _email = '', _password = ''; bool _isEditing = false; //是否為編輯狀態 bool _passwordNotVisible = true; - final TextEditingController _nameController = TextEditingController(); + final TextEditingController _realnameController = TextEditingController(); final TextEditingController _phoneController = TextEditingController(); final TextEditingController _genderController = TextEditingController(); final TextEditingController _addressController = TextEditingController(); @@ -60,12 +60,13 @@ class _PersonalInfoState extends State { //有資料 var row = result.rows.first; setState(() { - _name = row.colAt(0) ?? ''; //如果沒有資料就是空直 - _phone = row.colAt(1) ?? ''; - _gender = row.colAt(2) ?? ''; - _address = row.colAt(3) ?? ''; - _email = row.colAt(4) ?? ''; - _password = row.colAt(5) ?? ''; + _username =row.colAt(0)??''; + _realname = row.colAt(1) ?? ''; //如果沒有資料就是空直 + _phone = row.colAt(2) ?? ''; + _gender = row.colAt(3) ?? ''; + _address = row.colAt(4) ?? ''; + _email = row.colAt(5) ?? ''; + _password = row.colAt(6) ?? ''; }); } } catch (e) { @@ -79,7 +80,7 @@ class _PersonalInfoState extends State { setState(() { if (!_isEditing) { // 當進入編輯模式時,將當前的資料賦予控制器 - _nameController.text = _name; + _realnameController.text = _realname; _phoneController.text = _phone; _genderController.text = _gender; _addressController.text = _address; @@ -104,9 +105,9 @@ class _PersonalInfoState extends State { try { await conn.execute( - 'UPDATE HomeLogin SET homeName = :homeName, homePhone = :homePhone, homeGender = :homeGender, homeAddress = :homeAddress, homeEmail = :new_email, homePassword = :homePassword WHERE homeEmail = :old_email', + 'UPDATE HomeLogin SET homeRealName = :homeRealName , homePhone = :homePhone, homeGender = :homeGender, homeAddress = :homeAddress, homeEmail = :new_email, homePassword = :homePassword WHERE homeEmail = :old_email', { - 'homeName': _nameController.text, + 'homeRealName': _realnameController.text, 'homePhone': _phoneController.text, 'homeGender': _genderController.text, 'homeAddress': _addressController.text, @@ -116,7 +117,7 @@ class _PersonalInfoState extends State { }, ); setState(() { - _name = _nameController.text; + _realname = _realnameController.text; _phone = _phoneController.text; _gender = _genderController.text; _address = _addressController.text; @@ -124,7 +125,7 @@ class _PersonalInfoState extends State { _password = _passwordController.text; // 清空控制器內容 - _nameController.clear(); + _realnameController.clear(); _phoneController.clear(); _genderController.clear(); _addressController.clear(); @@ -184,12 +185,29 @@ class _PersonalInfoState extends State { padding: EdgeInsets.symmetric(vertical: 5), // 调整列表视图的 padding children: [ + ListTile( + title: Text( + '使用名稱', + style: TextStyle(fontSize: 20), + ), + subtitle: Text(_username), + ), + Divider(), ListTile( title: Text( '姓名', style: TextStyle(fontSize: 20), ), - subtitle: Text(_name), + subtitle: _isEditing + ? TextField( + controller: _realnameController, + onChanged: (value) { + setState(() { + _realname = value; + }); + }, + ) + : Text(_realname), ), Divider(), ListTile( @@ -310,6 +328,9 @@ class _PersonalInfoState extends State { shadowColor: Colors.transparent, ), ), + SizedBox( + height: 50, // 增加底部間距,確保按鈕不被遮蓋 + ), ], ), ),