個人資料加入username
This commit is contained in:
parent
114613ae0d
commit
31a12467ba
|
|
@ -14,7 +14,7 @@ class PersonalInfo extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _PersonalInfoState extends State<PersonalInfo> {
|
class _PersonalInfoState extends State<PersonalInfo> {
|
||||||
String _username='',_realname = '', _phone = '', _gender = '', _address = '', _email = '', _password = '';
|
String _username = '', _realname = '', _phone = '', _gender = '', _address = '', _email = '', _password = '';
|
||||||
|
|
||||||
bool _isEditing = false; //是否為編輯狀態
|
bool _isEditing = false; //是否為編輯狀態
|
||||||
bool _passwordNotVisible = true;
|
bool _passwordNotVisible = true;
|
||||||
|
|
@ -28,19 +28,15 @@ class _PersonalInfoState extends State<PersonalInfo> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
//初始化
|
|
||||||
super.initState();
|
super.initState();
|
||||||
print('狀態:$_isEditing');
|
|
||||||
_fetchData();
|
_fetchData();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchData() async {
|
void _fetchData() async {
|
||||||
//MYSQL
|
print('傳遞過來的 email: ${widget.email}');
|
||||||
print('傳遞過來的 email: ${widget.email}'); // 打印 email 來確認它是否正確傳遞
|
|
||||||
|
|
||||||
final conn = await MySQLConnection.createConnection(
|
final conn = await MySQLConnection.createConnection(
|
||||||
host: '203.64.84.154',
|
host: '203.64.84.154',
|
||||||
//127.0.0.1 10.0.2.2
|
|
||||||
port: 33061,
|
port: 33061,
|
||||||
userName: 'root',
|
userName: 'root',
|
||||||
password: 'Topic@2024',
|
password: 'Topic@2024',
|
||||||
|
|
@ -50,18 +46,15 @@ class _PersonalInfoState extends State<PersonalInfo> {
|
||||||
await conn.connect();
|
await conn.connect();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
print('ok');
|
|
||||||
print('狀態:$_isEditing');
|
|
||||||
var result = await conn.execute(
|
var result = await conn.execute(
|
||||||
'SELECT * FROM HomeLogin WHERE homeemail = :email',
|
'SELECT * FROM HomeLogin WHERE homeemail = :email',
|
||||||
{'email': widget.email}, // 傳入參數 email
|
{'email': widget.email},
|
||||||
);
|
);
|
||||||
if (result.rows.isNotEmpty) {
|
if (result.rows.isNotEmpty) {
|
||||||
//有資料
|
|
||||||
var row = result.rows.first;
|
var row = result.rows.first;
|
||||||
setState(() {
|
setState(() {
|
||||||
_username =row.colAt(0)??'';
|
_username = row.colAt(0) ?? '';
|
||||||
_realname = row.colAt(1) ?? ''; //如果沒有資料就是空直
|
_realname = row.colAt(1) ?? '';
|
||||||
_phone = row.colAt(2) ?? '';
|
_phone = row.colAt(2) ?? '';
|
||||||
_gender = row.colAt(3) ?? '';
|
_gender = row.colAt(3) ?? '';
|
||||||
_address = row.colAt(4) ?? '';
|
_address = row.colAt(4) ?? '';
|
||||||
|
|
@ -79,7 +72,6 @@ class _PersonalInfoState extends State<PersonalInfo> {
|
||||||
void _toggleEdit() {
|
void _toggleEdit() {
|
||||||
setState(() {
|
setState(() {
|
||||||
if (!_isEditing) {
|
if (!_isEditing) {
|
||||||
// 當進入編輯模式時,將當前的資料賦予控制器
|
|
||||||
_realnameController.text = _realname;
|
_realnameController.text = _realname;
|
||||||
_phoneController.text = _phone;
|
_phoneController.text = _phone;
|
||||||
_genderController.text = _gender;
|
_genderController.text = _gender;
|
||||||
|
|
@ -88,7 +80,6 @@ class _PersonalInfoState extends State<PersonalInfo> {
|
||||||
_passwordController.text = _password;
|
_passwordController.text = _password;
|
||||||
}
|
}
|
||||||
_isEditing = !_isEditing;
|
_isEditing = !_isEditing;
|
||||||
print('編輯狀態:$_isEditing');
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -112,7 +103,7 @@ class _PersonalInfoState extends State<PersonalInfo> {
|
||||||
'homeGender': _genderController.text,
|
'homeGender': _genderController.text,
|
||||||
'homeAddress': _addressController.text,
|
'homeAddress': _addressController.text,
|
||||||
'new_email': _emailController.text,
|
'new_email': _emailController.text,
|
||||||
'old_email': widget.email, // 用戶的舊 email 作為查找條件
|
'old_email': widget.email,
|
||||||
'homePassword': _passwordController.text,
|
'homePassword': _passwordController.text,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
@ -123,213 +114,117 @@ class _PersonalInfoState extends State<PersonalInfo> {
|
||||||
_address = _addressController.text;
|
_address = _addressController.text;
|
||||||
_email = _emailController.text;
|
_email = _emailController.text;
|
||||||
_password = _passwordController.text;
|
_password = _passwordController.text;
|
||||||
|
_isEditing = false;
|
||||||
// 清空控制器內容
|
|
||||||
_realnameController.clear();
|
|
||||||
_phoneController.clear();
|
|
||||||
_genderController.clear();
|
|
||||||
_addressController.clear();
|
|
||||||
_emailController.clear();
|
|
||||||
_passwordController.clear();
|
|
||||||
|
|
||||||
_isEditing = false; // 退出編輯
|
|
||||||
print('儲存狀態:$_isEditing');
|
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('Error: $e');
|
print('Error: $e');
|
||||||
} finally {
|
} finally {
|
||||||
await conn.close();
|
await conn.close();
|
||||||
print('finally儲存更新狀態:$_isEditing');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _loginOut() async {
|
void _loginOut() async {
|
||||||
print("loyout");
|
|
||||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
// remove all data in share preference(user data which save to identify user or others)
|
|
||||||
prefs.clear();
|
prefs.clear();
|
||||||
// navbar router setting
|
|
||||||
// replace screen with LoginPage and without navbar
|
|
||||||
pushReplacementWithoutNavBar(
|
pushReplacementWithoutNavBar(
|
||||||
context,
|
context,
|
||||||
NoSwipeBackRoute(
|
NoSwipeBackRoute(
|
||||||
builder: (context) => LoginPage(),
|
builder: (context) => LoginPage(),
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//頁面
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
// appBar: AppBar(
|
|
||||||
// title: Text('個人資料'),
|
|
||||||
// backgroundColor: Color(0xFFF5E3C3),
|
|
||||||
// ),
|
|
||||||
body: Column(
|
body: Column(
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
height: 100,
|
height: 120,
|
||||||
color: Color(0xFFF5E3C3),
|
color: Color(0xFFF5E3C3),
|
||||||
//背景底色
|
padding: EdgeInsets.only(top: 50, left: 20, right: 20),
|
||||||
width: double.infinity,
|
child: Row(
|
||||||
padding: EdgeInsets.all(10.0),
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
child: Center(
|
children: [
|
||||||
child: Text(
|
Text(
|
||||||
'個人資料',
|
_username + ' 您好',
|
||||||
style: TextStyle(fontSize: 24, height: 5),
|
style: TextStyle(fontSize: 28, color: Colors.black),
|
||||||
),
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: ListView(
|
child: ListView(
|
||||||
padding: EdgeInsets.symmetric(vertical: 5), // 调整列表视图的 padding
|
padding: EdgeInsets.symmetric(vertical: 5),
|
||||||
|
|
||||||
children: [
|
children: [
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(
|
leading: Icon(Icons.manage_accounts_outlined),
|
||||||
'使用名稱',
|
title: Text('基本資料', style: TextStyle(fontSize: 18)),
|
||||||
style: TextStyle(fontSize: 20),
|
onTap: () {
|
||||||
),
|
Navigator.push(
|
||||||
subtitle: Text(_username),
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => BasicInfoPage(
|
||||||
|
realname: _realname,
|
||||||
|
phone: _phone,
|
||||||
|
gender: _gender,
|
||||||
|
address: _address,
|
||||||
|
email: _email,
|
||||||
|
isEditing: _isEditing,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
Divider(),
|
Divider(),
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(
|
leading: Icon(Icons.lock_open_outlined),
|
||||||
'姓名',
|
title: Text('帳號設定', style: TextStyle(fontSize: 18)),
|
||||||
style: TextStyle(fontSize: 20),
|
onTap: () {
|
||||||
),
|
Navigator.push(
|
||||||
subtitle: _isEditing
|
context,
|
||||||
? TextField(
|
MaterialPageRoute(
|
||||||
controller: _realnameController,
|
builder: (context) => AccountPage(
|
||||||
onChanged: (value) {
|
email: _email,
|
||||||
setState(() {
|
password: _password,
|
||||||
_realname = value;
|
isEditing: _isEditing,
|
||||||
});
|
),
|
||||||
},
|
),
|
||||||
)
|
);
|
||||||
: Text(_realname),
|
},
|
||||||
),
|
),
|
||||||
Divider(),
|
Divider(),
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text('手機'),
|
leading: Icon(Icons.language_outlined),
|
||||||
subtitle: _isEditing
|
title: Text('語言設定', style: TextStyle(fontSize: 18)),
|
||||||
? TextField(
|
onTap: () {},
|
||||||
controller: _phoneController,
|
|
||||||
onChanged: (value) {
|
|
||||||
setState(() {
|
|
||||||
_phone = value;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
)
|
|
||||||
: Text(_phone),
|
|
||||||
),
|
),
|
||||||
Divider(),
|
Divider(),
|
||||||
ListTile(
|
|
||||||
title: Text('性別'),
|
|
||||||
subtitle: _isEditing
|
|
||||||
? TextField(
|
|
||||||
controller: _genderController,
|
|
||||||
onChanged: (value) {
|
|
||||||
setState(() {
|
|
||||||
_gender = value;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
)
|
|
||||||
: Text(_gender),
|
|
||||||
),
|
|
||||||
Divider(),
|
Divider(),
|
||||||
ListTile(
|
|
||||||
title: Text('地址'),
|
|
||||||
subtitle: _isEditing
|
|
||||||
? TextField(
|
|
||||||
controller: _addressController,
|
|
||||||
onChanged: (value) {
|
|
||||||
setState(() {
|
|
||||||
_address = value;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
)
|
|
||||||
: Text(_address),
|
|
||||||
),
|
|
||||||
Divider(),
|
|
||||||
ListTile(
|
|
||||||
title: Text('電子信箱'),
|
|
||||||
subtitle: _isEditing
|
|
||||||
? TextField(
|
|
||||||
controller: _emailController,
|
|
||||||
onChanged: (value) {
|
|
||||||
setState(() {
|
|
||||||
_email = value;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
)
|
|
||||||
: Text(_email),
|
|
||||||
),
|
|
||||||
Divider(),
|
|
||||||
ListTile(
|
|
||||||
title: Text('密碼'),
|
|
||||||
subtitle: _isEditing
|
|
||||||
? TextField(
|
|
||||||
controller: _passwordController,
|
|
||||||
obscureText: _passwordNotVisible,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
suffixIcon: IconButton(
|
|
||||||
icon: Icon(_passwordNotVisible
|
|
||||||
? Icons.visibility
|
|
||||||
: Icons.visibility_off),
|
|
||||||
onPressed: () {
|
|
||||||
setState(
|
|
||||||
() {
|
|
||||||
_passwordNotVisible = !_passwordNotVisible;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
)),
|
|
||||||
onChanged: (value) {
|
|
||||||
setState(() {
|
|
||||||
_password = value;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
)
|
|
||||||
: Text(_password),
|
|
||||||
),
|
|
||||||
Divider(),
|
|
||||||
SizedBox(
|
|
||||||
height: 20,
|
|
||||||
width: 60,
|
|
||||||
),
|
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
if (_isEditing) {
|
if (_isEditing) {
|
||||||
_saveChanges(); // 儲存變更
|
_saveChanges();
|
||||||
} else {
|
} else {
|
||||||
_toggleEdit(); // 進入編輯模式
|
_toggleEdit();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Text(_isEditing ? '儲存變更' : '修改資料'),
|
child: Text(_isEditing ? '儲存變更' : '修改資料'),
|
||||||
style: TextButton.styleFrom(
|
|
||||||
backgroundColor: Color(0xFFF5E3C3), // 無背景颜色
|
|
||||||
textStyle: TextStyle(fontSize: 18),
|
|
||||||
shadowColor: Colors.transparent, // 去除陰影
|
|
||||||
),
|
|
||||||
),
|
|
||||||
SizedBox(
|
|
||||||
height: 10,
|
|
||||||
width: 60,
|
|
||||||
),
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: () {
|
|
||||||
_loginOut();
|
|
||||||
},
|
|
||||||
child: Text('登出'),
|
|
||||||
style: TextButton.styleFrom(
|
style: TextButton.styleFrom(
|
||||||
backgroundColor: Color(0xFFF5E3C3),
|
backgroundColor: Color(0xFFF5E3C3),
|
||||||
textStyle: TextStyle(fontSize: 18),
|
textStyle: TextStyle(fontSize: 18),
|
||||||
shadowColor: Colors.transparent,
|
shadowColor: Colors.transparent,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(
|
ElevatedButton(
|
||||||
height: 50, // 增加底部間距,確保按鈕不被遮蓋
|
onPressed: _loginOut,
|
||||||
|
child: Text('登出'),
|
||||||
|
style: TextButton.styleFrom(
|
||||||
|
backgroundColor: Color(0xFFF5E3C3),
|
||||||
|
textStyle: TextStyle(fontSize: 18),
|
||||||
|
shadowColor: Colors.transparent,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
@ -339,3 +234,294 @@ class _PersonalInfoState extends State<PersonalInfo> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BasicInfoPage 類別
|
||||||
|
class BasicInfoPage extends StatefulWidget {
|
||||||
|
String realname;
|
||||||
|
String phone;
|
||||||
|
String gender;
|
||||||
|
String address;
|
||||||
|
String email;
|
||||||
|
bool isEditing;
|
||||||
|
|
||||||
|
BasicInfoPage({
|
||||||
|
required this.realname,
|
||||||
|
required this.phone,
|
||||||
|
required this.gender,
|
||||||
|
required this.address,
|
||||||
|
required this.email,
|
||||||
|
required this.isEditing,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
_BasicInfoPageState createState() => _BasicInfoPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _BasicInfoPageState extends State<BasicInfoPage> {
|
||||||
|
late TextEditingController _realnameController;
|
||||||
|
late TextEditingController _phoneController;
|
||||||
|
late TextEditingController _genderController;
|
||||||
|
late TextEditingController _addressController;
|
||||||
|
|
||||||
|
bool _isEditing = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_realnameController = TextEditingController(text: widget.realname);
|
||||||
|
_phoneController = TextEditingController(text: widget.phone);
|
||||||
|
_genderController = TextEditingController(text: widget.gender);
|
||||||
|
_addressController = TextEditingController(text: widget.address);
|
||||||
|
_isEditing = widget.isEditing;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _toggleEdit() {
|
||||||
|
setState(() {
|
||||||
|
_isEditing = !_isEditing;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _saveChanges() async {
|
||||||
|
final conn = await MySQLConnection.createConnection(
|
||||||
|
host: '203.64.84.154',
|
||||||
|
port: 33061,
|
||||||
|
userName: 'root',
|
||||||
|
password: 'Topic@2024',
|
||||||
|
databaseName: 'care',
|
||||||
|
);
|
||||||
|
|
||||||
|
await conn.connect();
|
||||||
|
|
||||||
|
try {
|
||||||
|
await conn.execute(
|
||||||
|
'UPDATE HomeLogin SET homeRealName = :homeRealName, homePhone = :homePhone, homeGender = :homeGender, homeAddress = :homeAddress WHERE homeEmail = :old_email',
|
||||||
|
{
|
||||||
|
'homeRealName': _realnameController.text,
|
||||||
|
'homePhone': _phoneController.text,
|
||||||
|
'homeGender': _genderController.text,
|
||||||
|
'homeAddress': _addressController.text,
|
||||||
|
'old_email': widget.email,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
setState(() {
|
||||||
|
widget.realname = _realnameController.text;
|
||||||
|
widget.phone = _phoneController.text;
|
||||||
|
widget.gender = _genderController.text;
|
||||||
|
widget.address = _addressController.text;
|
||||||
|
_isEditing = false;
|
||||||
|
});
|
||||||
|
print('successssssssssssssssss');
|
||||||
|
} catch (e) {
|
||||||
|
print('Error: $e');
|
||||||
|
} finally {
|
||||||
|
await conn.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text('基本資料'),
|
||||||
|
backgroundColor: Color(0xFFE0D0A9),
|
||||||
|
),
|
||||||
|
body: ListView(
|
||||||
|
padding: EdgeInsets.all(16),
|
||||||
|
children: [
|
||||||
|
ListTile(
|
||||||
|
title: Text('姓名'),
|
||||||
|
subtitle: _isEditing
|
||||||
|
? TextField(
|
||||||
|
controller: _realnameController,
|
||||||
|
)
|
||||||
|
: Text(widget.realname),
|
||||||
|
),
|
||||||
|
Divider(),
|
||||||
|
ListTile(
|
||||||
|
title: Text('手機'),
|
||||||
|
subtitle: _isEditing
|
||||||
|
? TextField(
|
||||||
|
controller: _phoneController,
|
||||||
|
)
|
||||||
|
: Text(widget.phone),
|
||||||
|
),
|
||||||
|
Divider(),
|
||||||
|
ListTile(
|
||||||
|
title: Text('性別'),
|
||||||
|
subtitle: _isEditing
|
||||||
|
? TextField(
|
||||||
|
controller: _genderController,
|
||||||
|
)
|
||||||
|
: Text(widget.gender),
|
||||||
|
),
|
||||||
|
Divider(),
|
||||||
|
ListTile(
|
||||||
|
title: Text('地址'),
|
||||||
|
subtitle: _isEditing
|
||||||
|
? TextField(
|
||||||
|
controller: _addressController,
|
||||||
|
)
|
||||||
|
: Text(widget.address),
|
||||||
|
),
|
||||||
|
SizedBox(height: 20),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
|
if (_isEditing) {
|
||||||
|
_saveChanges();
|
||||||
|
} else {
|
||||||
|
_toggleEdit();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: Text(_isEditing ? '儲存變更' : '修改資料'),
|
||||||
|
style: TextButton.styleFrom(
|
||||||
|
backgroundColor: Color(0xFFF5E3C3),
|
||||||
|
textStyle: TextStyle(fontSize: 18),
|
||||||
|
shadowColor: Colors.transparent,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BasicInfoPage 類別
|
||||||
|
class AccountPage extends StatefulWidget {
|
||||||
|
String email;
|
||||||
|
String password;
|
||||||
|
bool isEditing;
|
||||||
|
|
||||||
|
AccountPage({
|
||||||
|
required this.email,
|
||||||
|
required this.password,
|
||||||
|
required this.isEditing,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
_AccountPageState createState() => _AccountPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _AccountPageState extends State<AccountPage> {
|
||||||
|
late TextEditingController _emailController;
|
||||||
|
late TextEditingController _passwordController;
|
||||||
|
|
||||||
|
bool _isEditing = false;
|
||||||
|
bool _passwordNotVisible = true; // 需要加上這行,來處理密碼可見性切換
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_emailController = TextEditingController(text: widget.email);
|
||||||
|
_passwordController = TextEditingController(text: widget.password);
|
||||||
|
_isEditing = widget.isEditing;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _toggleEdit() {
|
||||||
|
setState(() {
|
||||||
|
_isEditing = !_isEditing;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _saveChanges() async {
|
||||||
|
final conn = await MySQLConnection.createConnection(
|
||||||
|
host: '203.64.84.154',
|
||||||
|
port: 33061,
|
||||||
|
userName: 'root',
|
||||||
|
password: 'Topic@2024',
|
||||||
|
databaseName: 'care',
|
||||||
|
);
|
||||||
|
|
||||||
|
await conn.connect();
|
||||||
|
print('connectttttttttttttttttttttttttt');
|
||||||
|
|
||||||
|
try {
|
||||||
|
await conn.execute(
|
||||||
|
'UPDATE HomeLogin SET homeEmail = :homeEmail,homePassword= :homePassword WHERE homeEmail = :old_email',
|
||||||
|
{
|
||||||
|
'homeEmail': _emailController.text,
|
||||||
|
'homePassword': _passwordController.text,
|
||||||
|
'old_email': widget.email,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
setState(() {
|
||||||
|
widget.email = _emailController.text;
|
||||||
|
widget.password = _passwordController.text;
|
||||||
|
_isEditing = false;
|
||||||
|
});
|
||||||
|
print('資料更新成功');
|
||||||
|
} catch (e) {
|
||||||
|
print('Error: $e');
|
||||||
|
} finally {
|
||||||
|
await conn.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text('帳號設定'),
|
||||||
|
backgroundColor: Color(0xFFE0D0A9),
|
||||||
|
),
|
||||||
|
body: ListView(
|
||||||
|
padding: EdgeInsets.all(16),
|
||||||
|
children: [ListTile(
|
||||||
|
title: Text('電子信箱'),
|
||||||
|
subtitle: _isEditing
|
||||||
|
? TextField(
|
||||||
|
controller: _emailController,
|
||||||
|
onChanged: (value) {
|
||||||
|
setState(() {
|
||||||
|
widget.email = value;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
)
|
||||||
|
: Text(widget.email),
|
||||||
|
),
|
||||||
|
Divider(),
|
||||||
|
ListTile(
|
||||||
|
title: Text('密碼'),
|
||||||
|
subtitle: _isEditing
|
||||||
|
? TextField(
|
||||||
|
controller: _passwordController,
|
||||||
|
obscureText: _passwordNotVisible,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
suffixIcon: IconButton(
|
||||||
|
icon: Icon(_passwordNotVisible ? Icons.visibility : Icons.visibility_off),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
_passwordNotVisible = !_passwordNotVisible;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
onChanged: (value) {
|
||||||
|
setState(() {
|
||||||
|
widget.password = value;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
)
|
||||||
|
: Text(widget.password),
|
||||||
|
),
|
||||||
|
SizedBox(height: 20),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
|
if (_isEditing) {
|
||||||
|
_saveChanges();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_toggleEdit();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: Text(_isEditing ? '儲存變更' : '修改資料'),
|
||||||
|
style: TextButton.styleFrom(
|
||||||
|
backgroundColor: Color(0xFFF5E3C3),
|
||||||
|
textStyle: TextStyle(fontSize: 18),
|
||||||
|
shadowColor: Colors.transparent,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user