更改資料庫連接,testdb->care

This commit is contained in:
kuei
2024-09-04 08:26:22 +08:00
parent 10d856208d
commit 968ef745a2

View File

@@ -18,7 +18,7 @@ class PersonalInfo extends StatefulWidget {
}
class _PersonalInfoState extends State<PersonalInfo> {
String _name = '', _phone = '', _age = '', _gender = '', _email = '';
String _name = '', _phone = '', _gender = '', _address='', _email = '', _password = '';
bool _isEditing = false; //是否為編輯狀態
final TextEditingController _emailController =
TextEditingController(); //email輸入text
@@ -35,15 +35,15 @@ class _PersonalInfoState extends State<PersonalInfo> {
print('傳遞過來的 email: ${widget.email}'); // 打印 email 來確認它是否正確傳遞
final conn = await MySQLConnection.createConnection(
//host: '203.64.84.154',
host: '10.0.2.2',
host: '203.64.84.154',
//host: '10.0.2.2',
//127.0.0.1 10.0.2.2
port: 3306,
port: 33061,
userName: 'root',
//password: 'Topic@2024',
password: '0000',
//databaseName: 'care', //testdb
databaseName: 'testdb',
password: 'Topic@2024',
//password: '0000',
databaseName: 'care', //testdb
//databaseName: 'testdb',
);
await conn.connect();
@@ -51,18 +51,19 @@ class _PersonalInfoState extends State<PersonalInfo> {
try {
print('ok');
var result = await conn.execute(
'SELECT name, phone, age, gender, email FROM users WHERE email = :email',
'SELECT * FROM HomeLogin WHERE homeemail = :email',
{'email': widget.email}, // 傳入參數 email
);
if (result.rows.isNotEmpty) {
//有資料
var row = result.rows.first;
setState(() {
_name = row.colAt(0) ?? ''; //如果沒有資料就是空直
_phone = row.colAt(1) ?? '';
_age = row.colAt(2) ?? '';
_gender = row.colAt(3) ?? '';
_email = row.colAt(4) ?? '';
_name = row.colAt(0)??'';//如果沒有資料就是空直
_phone = row.colAt(1)??'';
_gender = row.colAt(2)??'';
_address = row.colAt(3)??'';
_email = row.colAt(4)??'';
_password = row.colAt(5)??'';
});
}
} catch (e) {
@@ -79,19 +80,19 @@ class _PersonalInfoState extends State<PersonalInfo> {
}
void _saveChanges() async {
final conn = await MySQLConnection.createConnection(
host: '10.0.2.2',
port: 3306,
/*final conn = await MySQLConnection.createConnection(
host: '203.64.84.154',
port: 33061,
userName: 'root',
password: '0000',
databaseName: 'testdb',
password: 'Topic@2024',
databaseName: 'care',
);
await conn.connect();
await conn.connect();*/
try {
await conn.execute(
'UPDATE users SET email = :email WHERE email = :old_email',
'UPDATE HomeLogin SET homeemail = :email WHERE homeemail = :old_email',
{'email': _emailController.text, 'old_email': widget.email},
);
setState(() {
@@ -106,6 +107,7 @@ class _PersonalInfoState extends State<PersonalInfo> {
}
void _loginOut() async {
print("loyout");
SharedPreferences prefs = await SharedPreferences.getInstance();
// remove all data in share preference(user data which save to identify user or others)
prefs.clear();
@@ -164,13 +166,6 @@ class _PersonalInfoState extends State<PersonalInfo> {
onTap: () {},
),
Divider(),
ListTile(
title: Text('生日'),
subtitle: Text(_age),
//trailing: Icon(Icons.arrow_forward_ios),
onTap: () {},
),
Divider(),
ListTile(
title: Text('性別'),
subtitle: Text(_gender),
@@ -179,26 +174,39 @@ class _PersonalInfoState extends State<PersonalInfo> {
),
Divider(),
ListTile(
title: Text('EMAIL'),
subtitle: //Text(_email),
_isEditing
? TextField(
controller: _emailController,
autofocus: true,
onChanged: (value) {
setState(() {
_email = value;
});
},
)
: Text(_email),
title: Text('地址'),
subtitle: Text(_address),
//trailing: Icon(Icons.arrow_forward_ios),
onTap: () {},
),
Divider(),
ListTile(
title: Text('電子信箱'),
subtitle: _isEditing
? TextField(
controller: _emailController,
autofocus: true,
onChanged: (value) {
setState(() {
_email = value;
});
},
)
: Text(_email),
//trailing: Icon(Icons.arrow_forward_ios),
onTap: () {
_toggleEdit(); // 切換到編輯狀態
},
),
Divider(),
ListTile(
title: Text('密碼'),
subtitle: Text(_password),
//trailing: Icon(Icons.arrow_forward_ios),
onTap: () {
},
),
Divider(),
SizedBox(
height: 20,
width: 60,