Compare commits
No commits in common. "d2a2030979714e7d5ff606d097f0af7634cf09f6" and "10d856208d678d7e071b13534d6c5dab6e4fe17f" have entirely different histories.
d2a2030979
...
10d856208d
|
|
@ -29,20 +29,20 @@ class _HistoricalRecordState extends State<HistoricalRecord> {
|
||||||
print('connect');
|
print('connect');
|
||||||
|
|
||||||
final conn = await MySQLConnection.createConnection(
|
final conn = await MySQLConnection.createConnection(
|
||||||
host: '203.64.84.154',
|
//host: '203.64.84.154',
|
||||||
//host: '10.0.2.2',
|
host: '10.0.2.2',
|
||||||
//127.0.0.1 10.0.2.2
|
//127.0.0.1 10.0.2.2
|
||||||
port: 33061,
|
port: 3306,
|
||||||
userName: 'root',
|
userName: 'root',
|
||||||
password: 'Topic@2024',
|
//password: 'Topic@2024',
|
||||||
//password: '0000',
|
password: '0000',
|
||||||
databaseName: 'care', //testdb
|
//databaseName: 'care', //testdb
|
||||||
//databaseName: 'testdb',
|
databaseName: 'testdb',
|
||||||
);
|
);
|
||||||
await conn.connect();
|
await conn.connect();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var result = await conn.execute('SELECT HomeElderFall.*, HomeElder.heName FROM HomeElderFall JOIN HomeElder ON HomeElderFall.heId = HomeElder.heId;');
|
var result = await conn.execute('SELECT * FROM users');
|
||||||
print('Result: ${result.length} rows found.');
|
print('Result: ${result.length} rows found.');
|
||||||
|
|
||||||
if (result.rows.isEmpty) {
|
if (result.rows.isEmpty) {
|
||||||
|
|
@ -51,12 +51,14 @@ class _HistoricalRecordState extends State<HistoricalRecord> {
|
||||||
setState(() {
|
setState(() {
|
||||||
_results = result.rows
|
_results = result.rows
|
||||||
.map((row) => {
|
.map((row) => {
|
||||||
'長者ID': row.colAt(0),//去裝資料庫的行數
|
'id': row.colAt(0),
|
||||||
'姓名': row.colAt(8),
|
'name': row.colAt(1),
|
||||||
'跌倒時間': row.colAt(1),
|
'age': row.colAt(2),
|
||||||
'跌倒原因': row.colAt(2),
|
'gender': row.colAt(3),
|
||||||
'跌倒地點': row.colAt(7),
|
'phone': row.colAt(4),
|
||||||
})
|
'email': row.colAt(5),
|
||||||
|
'password': row.colAt(2)
|
||||||
|
})
|
||||||
.toList();
|
.toList();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -91,12 +93,12 @@ class _HistoricalRecordState extends State<HistoricalRecord> {
|
||||||
itemCount: _results.length,
|
itemCount: _results.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(_results[index]['姓名']),
|
title: Text(_results[index]['name']),
|
||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
'長者ID: ${_results[index]['長者ID']}\n, '
|
'age: ${_results[index]['age']}, '
|
||||||
'跌倒時間: ${_results[index]['跌倒時間']}\n, '
|
'gender: ${_results[index]['gender']}, '
|
||||||
'跌倒原因: ${_results[index]['跌倒原因']}\n, '
|
'phone: ${_results[index]['phone']}, '
|
||||||
'跌倒地點: ${_results[index]['跌倒地點']}\n',
|
'email: ${_results[index]['email']}',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -146,14 +146,10 @@ class _HomePageState extends State<HomePage> {
|
||||||
initTabIndex: 2,
|
initTabIndex: 2,
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
} else if (label == '切換畫面') {
|
} else if (label == '123') {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute
|
MaterialPageRoute(builder: (context) => TryPage()),
|
||||||
(builder: (context) => BottomNavBar(
|
|
||||||
email: widget.email,
|
|
||||||
initTabIndex: 3,
|
|
||||||
)),
|
|
||||||
);
|
);
|
||||||
} else if (label == '個人資料') {
|
} else if (label == '個人資料') {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:mysql_client/mysql_client.dart';
|
import 'package:mysql_client/mysql_client.dart';
|
||||||
import 'package:webview_flutter/webview_flutter.dart';
|
|
||||||
|
|
||||||
import 'BottomNavBar.dart';
|
|
||||||
class MessagePage extends StatefulWidget {
|
class MessagePage extends StatefulWidget {
|
||||||
final String email; // 接收來自上個頁面的 email
|
final String email; // 接收來自上個頁面的 email
|
||||||
|
|
||||||
|
|
@ -13,166 +11,84 @@ class MessagePage extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MessagePageState extends State<MessagePage> {
|
class _MessagePageState extends State<MessagePage> {
|
||||||
late WebViewController _webViewController;
|
List<Map<String, dynamic>> _results = [];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
_fetchData(); // 連接資料庫並抓取資料
|
||||||
|
}
|
||||||
|
|
||||||
|
void _fetchData() async {
|
||||||
|
print('connect');
|
||||||
|
|
||||||
|
final conn = await MySQLConnection.createConnection(
|
||||||
|
host: '203.64.84.154',
|
||||||
|
port: 33061,
|
||||||
|
userName: 'root',
|
||||||
|
password: 'Topic@2024',
|
||||||
|
databaseName: 'care',
|
||||||
|
);
|
||||||
|
await conn.connect();
|
||||||
|
|
||||||
|
try {
|
||||||
|
var result = await conn.execute('SELECT eName, eGender FROM Elder');
|
||||||
|
print('Result: ${result.length} rows found.');
|
||||||
|
|
||||||
|
if (result.rows.isEmpty) {
|
||||||
|
print('No data found in users table.');
|
||||||
|
} else {
|
||||||
|
setState(() {
|
||||||
|
_results = result.rows
|
||||||
|
.map((row) => {
|
||||||
|
'name': row.colAt(0),
|
||||||
|
'gender': row.colAt(1),
|
||||||
|
})
|
||||||
|
.toList();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
print('Error: $e');
|
||||||
|
} finally {
|
||||||
|
await conn.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return PopScope(
|
return Scaffold(
|
||||||
child: Scaffold(
|
/*appBar: AppBar(
|
||||||
body: Center(
|
title: Text('MySQL Data'), // 顯示標題
|
||||||
child: Column(
|
backgroundColor: Color(0xFFF5E3C3),
|
||||||
children: [
|
),*/
|
||||||
Container(
|
body: Column(
|
||||||
height: 100,
|
children: [
|
||||||
// APPBar height
|
Container(
|
||||||
color: Color(0xFFF5E3C3),
|
height: 100,
|
||||||
width: double.infinity,
|
color: Color(0xFFF5E3C3),
|
||||||
padding: EdgeInsets.all(10.0),
|
width: double.infinity,
|
||||||
child: Stack(children: [
|
padding: EdgeInsets.all(10.0),
|
||||||
Container(
|
child: Center(
|
||||||
padding: EdgeInsets.only(
|
child: Text(
|
||||||
left: MediaQuery.of(context).size.width,
|
'切換畫面',
|
||||||
top: MediaQuery.of(context).size.height / 2,
|
style: TextStyle(fontSize: 24, height: 5),
|
||||||
),
|
|
||||||
child: Icon(Icons.settings, size: 48, color: Colors.orange),
|
|
||||||
),
|
|
||||||
Center(
|
|
||||||
child: Text(
|
|
||||||
'全方位照護守護者',
|
|
||||||
style: TextStyle(fontSize: 24, height: 5),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
])),
|
|
||||||
Container(
|
|
||||||
color: Color(0xFFFFF0E0),
|
|
||||||
margin: EdgeInsets.only(top: 5),
|
|
||||||
padding: EdgeInsets.all(16),
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
Container(
|
|
||||||
height: 240,
|
|
||||||
width: double.infinity,
|
|
||||||
// TODO: 如果用http需要分別設定ios, android權限
|
|
||||||
// TODO: 替換video_player to flutter_webView
|
|
||||||
child: WebViewWidget(
|
|
||||||
controller: WebViewController()
|
|
||||||
..setJavaScriptMode(JavaScriptMode.unrestricted)
|
|
||||||
..setNavigationDelegate(
|
|
||||||
NavigationDelegate(
|
|
||||||
onProgress: (int progress) {
|
|
||||||
// Update loading bar.
|
|
||||||
},
|
|
||||||
onPageStarted: (String url) {},
|
|
||||||
onPageFinished: (String url) {},
|
|
||||||
onHttpError: (HttpResponseError error) {
|
|
||||||
print("httpError");
|
|
||||||
},
|
|
||||||
onWebResourceError: (WebResourceError error) {
|
|
||||||
print("httpResourceError");
|
|
||||||
print(error.description);
|
|
||||||
},
|
|
||||||
onNavigationRequest: (NavigationRequest request) {
|
|
||||||
if (request.url.startsWith(
|
|
||||||
'http://203.64.84.154:8088/video_feed')) {
|
|
||||||
return NavigationDecision.prevent;
|
|
||||||
}
|
|
||||||
return NavigationDecision.navigate;
|
|
||||||
},
|
|
||||||
),
|
|
||||||
)
|
|
||||||
..loadRequest(Uri.parse('http://203.64.84.154:8088')),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
'即時畫面',
|
|
||||||
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
Expanded(
|
),
|
||||||
child: GridView.count(
|
|
||||||
crossAxisCount: 2,
|
|
||||||
shrinkWrap: true,
|
|
||||||
physics: NeverScrollableScrollPhysics(),
|
|
||||||
padding: EdgeInsets.all(16),
|
|
||||||
children: [
|
|
||||||
_buildGridItem(Icons.monitor_outlined, '畫面1', context),
|
|
||||||
_buildGridItem(Icons.monitor_outlined, '畫面2', context),
|
|
||||||
/*_buildGridItem(Icons.monitor_outlined, '切換畫面', context),
|
|
||||||
_buildGridItem(Icons.person_sharp, '個人資料', context),*/
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
Expanded(
|
||||||
),
|
child: ListView.builder(
|
||||||
canPop: false,
|
padding: EdgeInsets.symmetric(vertical: 5), // 调整列表视图的 padding
|
||||||
);
|
itemCount: _results.length, // 列表項目數量
|
||||||
}
|
itemBuilder: (context, index) {
|
||||||
|
final user = _results[index];
|
||||||
Widget _buildGridItem(IconData icon, String label, BuildContext context) {
|
return ListTile(
|
||||||
return Card(
|
title: Text(user['name']), // 顯示名稱
|
||||||
shape: RoundedRectangleBorder(
|
subtitle: Text('gender: ${user['gender']}'), // 顯示性別
|
||||||
borderRadius: BorderRadius.circular(20),
|
);
|
||||||
),
|
},
|
||||||
color: Colors.white,
|
),
|
||||||
child: InkWell(
|
|
||||||
onTap: () {
|
|
||||||
/*if (label == '跌倒紀錄') {
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) => BottomNavBar(
|
|
||||||
email: widget.email,
|
|
||||||
initTabIndex: 1,
|
|
||||||
)),
|
|
||||||
);
|
|
||||||
} else if (label == '知識補充') {
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) => BottomNavBar(
|
|
||||||
email: widget.email,
|
|
||||||
initTabIndex: 2,
|
|
||||||
)),
|
|
||||||
);
|
|
||||||
} else if (label == '切換畫面') {
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute
|
|
||||||
(builder: (context) => BottomNavBar(
|
|
||||||
email: widget.email,
|
|
||||||
initTabIndex: 3,
|
|
||||||
)),
|
|
||||||
);
|
|
||||||
} else if (label == '個人資料') {
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) => BottomNavBar(
|
|
||||||
email: widget.email,
|
|
||||||
initTabIndex: 4,
|
|
||||||
)),
|
|
||||||
);
|
|
||||||
}*/
|
|
||||||
},
|
|
||||||
child: Center(
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
Icon(icon, size: 48, color: Colors.orange),
|
|
||||||
SizedBox(height: 8),
|
|
||||||
Text(label, style: TextStyle(fontSize: 16)),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ class PersonalInfo extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _PersonalInfoState extends State<PersonalInfo> {
|
class _PersonalInfoState extends State<PersonalInfo> {
|
||||||
String _name = '', _phone = '', _gender = '', _address='', _email = '', _password = '';
|
String _name = '', _phone = '', _age = '', _gender = '', _email = '';
|
||||||
bool _isEditing = false; //是否為編輯狀態
|
bool _isEditing = false; //是否為編輯狀態
|
||||||
final TextEditingController _emailController =
|
final TextEditingController _emailController =
|
||||||
TextEditingController(); //email輸入text
|
TextEditingController(); //email輸入text
|
||||||
|
|
@ -35,15 +35,15 @@ class _PersonalInfoState extends State<PersonalInfo> {
|
||||||
print('傳遞過來的 email: ${widget.email}'); // 打印 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',
|
||||||
//host: '10.0.2.2',
|
host: '10.0.2.2',
|
||||||
//127.0.0.1 10.0.2.2
|
//127.0.0.1 10.0.2.2
|
||||||
port: 33061,
|
port: 3306,
|
||||||
userName: 'root',
|
userName: 'root',
|
||||||
password: 'Topic@2024',
|
//password: 'Topic@2024',
|
||||||
//password: '0000',
|
password: '0000',
|
||||||
databaseName: 'care', //testdb
|
//databaseName: 'care', //testdb
|
||||||
//databaseName: 'testdb',
|
databaseName: 'testdb',
|
||||||
);
|
);
|
||||||
|
|
||||||
await conn.connect();
|
await conn.connect();
|
||||||
|
|
@ -51,19 +51,18 @@ class _PersonalInfoState extends State<PersonalInfo> {
|
||||||
try {
|
try {
|
||||||
print('ok');
|
print('ok');
|
||||||
var result = await conn.execute(
|
var result = await conn.execute(
|
||||||
'SELECT * FROM HomeLogin WHERE homeemail = :email',
|
'SELECT name, phone, age, gender, email FROM users WHERE email = :email',
|
||||||
{'email': widget.email}, // 傳入參數 email
|
{'email': widget.email}, // 傳入參數 email
|
||||||
);
|
);
|
||||||
if (result.rows.isNotEmpty) {
|
if (result.rows.isNotEmpty) {
|
||||||
//有資料
|
//有資料
|
||||||
var row = result.rows.first;
|
var row = result.rows.first;
|
||||||
setState(() {
|
setState(() {
|
||||||
_name = row.colAt(0)??'';//如果沒有資料就是空直
|
_name = row.colAt(0) ?? ''; //如果沒有資料就是空直
|
||||||
_phone = row.colAt(1)??'';
|
_phone = row.colAt(1) ?? '';
|
||||||
_gender = row.colAt(2)??'';
|
_age = row.colAt(2) ?? '';
|
||||||
_address = row.colAt(3)??'';
|
_gender = row.colAt(3) ?? '';
|
||||||
_email = row.colAt(4)??'';
|
_email = row.colAt(4) ?? '';
|
||||||
_password = row.colAt(5)??'';
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
@ -81,18 +80,18 @@ class _PersonalInfoState extends State<PersonalInfo> {
|
||||||
|
|
||||||
void _saveChanges() async {
|
void _saveChanges() async {
|
||||||
final conn = await MySQLConnection.createConnection(
|
final conn = await MySQLConnection.createConnection(
|
||||||
host: '203.64.84.154',
|
host: '10.0.2.2',
|
||||||
port: 33061,
|
port: 3306,
|
||||||
userName: 'root',
|
userName: 'root',
|
||||||
password: 'Topic@2024',
|
password: '0000',
|
||||||
databaseName: 'care',
|
databaseName: 'testdb',
|
||||||
);
|
);
|
||||||
|
|
||||||
await conn.connect();
|
await conn.connect();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await conn.execute(
|
await conn.execute(
|
||||||
'UPDATE HomeLogin SET homeemail = :email WHERE homeemail = :old_email',
|
'UPDATE users SET email = :email WHERE email = :old_email',
|
||||||
{'email': _emailController.text, 'old_email': widget.email},
|
{'email': _emailController.text, 'old_email': widget.email},
|
||||||
);
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
|
|
@ -107,7 +106,6 @@ class _PersonalInfoState extends State<PersonalInfo> {
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
// remove all data in share preference(user data which save to identify user or others)
|
||||||
prefs.clear();
|
prefs.clear();
|
||||||
|
|
@ -166,6 +164,13 @@ class _PersonalInfoState extends State<PersonalInfo> {
|
||||||
onTap: () {},
|
onTap: () {},
|
||||||
),
|
),
|
||||||
Divider(),
|
Divider(),
|
||||||
|
ListTile(
|
||||||
|
title: Text('生日'),
|
||||||
|
subtitle: Text(_age),
|
||||||
|
//trailing: Icon(Icons.arrow_forward_ios),
|
||||||
|
onTap: () {},
|
||||||
|
),
|
||||||
|
Divider(),
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text('性別'),
|
title: Text('性別'),
|
||||||
subtitle: Text(_gender),
|
subtitle: Text(_gender),
|
||||||
|
|
@ -174,39 +179,26 @@ class _PersonalInfoState extends State<PersonalInfo> {
|
||||||
),
|
),
|
||||||
Divider(),
|
Divider(),
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text('地址'),
|
title: Text('EMAIL'),
|
||||||
subtitle: Text(_address),
|
subtitle: //Text(_email),
|
||||||
//trailing: Icon(Icons.arrow_forward_ios),
|
_isEditing
|
||||||
onTap: () {},
|
? TextField(
|
||||||
),
|
controller: _emailController,
|
||||||
Divider(),
|
autofocus: true,
|
||||||
ListTile(
|
onChanged: (value) {
|
||||||
title: Text('電子信箱'),
|
setState(() {
|
||||||
subtitle: _isEditing
|
_email = value;
|
||||||
? TextField(
|
});
|
||||||
controller: _emailController,
|
},
|
||||||
autofocus: true,
|
)
|
||||||
onChanged: (value) {
|
: Text(_email),
|
||||||
setState(() {
|
|
||||||
_email = value;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
)
|
|
||||||
: Text(_email),
|
|
||||||
//trailing: Icon(Icons.arrow_forward_ios),
|
//trailing: Icon(Icons.arrow_forward_ios),
|
||||||
|
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_toggleEdit(); // 切換到編輯狀態
|
_toggleEdit(); // 切換到編輯狀態
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Divider(),
|
Divider(),
|
||||||
ListTile(
|
|
||||||
title: Text('密碼'),
|
|
||||||
subtitle: Text(_password),
|
|
||||||
//trailing: Icon(Icons.arrow_forward_ios),
|
|
||||||
onTap: () {
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Divider(),
|
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: 20,
|
height: 20,
|
||||||
width: 60,
|
width: 60,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user