Compare commits
3 Commits
10d856208d
...
d2a2030979
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d2a2030979 | ||
|
|
7fb6d59c1c | ||
|
|
968ef745a2 |
|
|
@ -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: 3306,
|
port: 33061,
|
||||||
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 * FROM users');
|
var result = await conn.execute('SELECT HomeElderFall.*, HomeElder.heName FROM HomeElderFall JOIN HomeElder ON HomeElderFall.heId = HomeElder.heId;');
|
||||||
print('Result: ${result.length} rows found.');
|
print('Result: ${result.length} rows found.');
|
||||||
|
|
||||||
if (result.rows.isEmpty) {
|
if (result.rows.isEmpty) {
|
||||||
|
|
@ -51,13 +51,11 @@ 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),//去裝資料庫的行數
|
||||||
'name': row.colAt(1),
|
'姓名': row.colAt(8),
|
||||||
'age': row.colAt(2),
|
'跌倒時間': row.colAt(1),
|
||||||
'gender': row.colAt(3),
|
'跌倒原因': row.colAt(2),
|
||||||
'phone': row.colAt(4),
|
'跌倒地點': row.colAt(7),
|
||||||
'email': row.colAt(5),
|
|
||||||
'password': row.colAt(2)
|
|
||||||
})
|
})
|
||||||
.toList();
|
.toList();
|
||||||
});
|
});
|
||||||
|
|
@ -93,12 +91,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]['name']),
|
title: Text(_results[index]['姓名']),
|
||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
'age: ${_results[index]['age']}, '
|
'長者ID: ${_results[index]['長者ID']}\n, '
|
||||||
'gender: ${_results[index]['gender']}, '
|
'跌倒時間: ${_results[index]['跌倒時間']}\n, '
|
||||||
'phone: ${_results[index]['phone']}, '
|
'跌倒原因: ${_results[index]['跌倒原因']}\n, '
|
||||||
'email: ${_results[index]['email']}',
|
'跌倒地點: ${_results[index]['跌倒地點']}\n',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -146,10 +146,14 @@ class _HomePageState extends State<HomePage> {
|
||||||
initTabIndex: 2,
|
initTabIndex: 2,
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
} else if (label == '123') {
|
} else if (label == '切換畫面') {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => TryPage()),
|
MaterialPageRoute
|
||||||
|
(builder: (context) => BottomNavBar(
|
||||||
|
email: widget.email,
|
||||||
|
initTabIndex: 3,
|
||||||
|
)),
|
||||||
);
|
);
|
||||||
} else if (label == '個人資料') {
|
} else if (label == '個人資料') {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
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
|
||||||
|
|
||||||
|
|
@ -11,85 +13,167 @@ class MessagePage extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MessagePageState extends State<MessagePage> {
|
class _MessagePageState extends State<MessagePage> {
|
||||||
List<Map<String, dynamic>> _results = [];
|
late WebViewController _webViewController;
|
||||||
|
|
||||||
@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 Scaffold(
|
return PopScope(
|
||||||
/*appBar: AppBar(
|
child: Scaffold(
|
||||||
title: Text('MySQL Data'), // 顯示標題
|
body: Center(
|
||||||
backgroundColor: Color(0xFFF5E3C3),
|
child: Column(
|
||||||
),*/
|
|
||||||
body: Column(
|
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
height: 100,
|
height: 100,
|
||||||
|
// APPBar height
|
||||||
color: Color(0xFFF5E3C3),
|
color: Color(0xFFF5E3C3),
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
padding: EdgeInsets.all(10.0),
|
padding: EdgeInsets.all(10.0),
|
||||||
child: Center(
|
child: Stack(children: [
|
||||||
|
Container(
|
||||||
|
padding: EdgeInsets.only(
|
||||||
|
left: MediaQuery.of(context).size.width,
|
||||||
|
top: MediaQuery.of(context).size.height / 2,
|
||||||
|
),
|
||||||
|
child: Icon(Icons.settings, size: 48, color: Colors.orange),
|
||||||
|
),
|
||||||
|
Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
'切換畫面',
|
'全方位照護守護者',
|
||||||
style: TextStyle(fontSize: 24, height: 5),
|
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(
|
Expanded(
|
||||||
child: ListView.builder(
|
child: GridView.count(
|
||||||
padding: EdgeInsets.symmetric(vertical: 5), // 调整列表视图的 padding
|
crossAxisCount: 2,
|
||||||
itemCount: _results.length, // 列表項目數量
|
shrinkWrap: true,
|
||||||
itemBuilder: (context, index) {
|
physics: NeverScrollableScrollPhysics(),
|
||||||
final user = _results[index];
|
padding: EdgeInsets.all(16),
|
||||||
return ListTile(
|
children: [
|
||||||
title: Text(user['name']), // 顯示名稱
|
_buildGridItem(Icons.monitor_outlined, '畫面1', context),
|
||||||
subtitle: Text('gender: ${user['gender']}'), // 顯示性別
|
_buildGridItem(Icons.monitor_outlined, '畫面2', context),
|
||||||
);
|
/*_buildGridItem(Icons.monitor_outlined, '切換畫面', context),
|
||||||
},
|
_buildGridItem(Icons.person_sharp, '個人資料', context),*/
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
canPop: false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildGridItem(IconData icon, String label, BuildContext context) {
|
||||||
|
return Card(
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
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 = '', _age = '', _gender = '', _email = '';
|
String _name = '', _phone = '', _gender = '', _address='', _email = '', _password = '';
|
||||||
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: 3306,
|
port: 33061,
|
||||||
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,18 +51,19 @@ class _PersonalInfoState extends State<PersonalInfo> {
|
||||||
try {
|
try {
|
||||||
print('ok');
|
print('ok');
|
||||||
var result = await conn.execute(
|
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
|
{'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)??'';
|
||||||
_age = row.colAt(2) ?? '';
|
_gender = row.colAt(2)??'';
|
||||||
_gender = row.colAt(3) ?? '';
|
_address = row.colAt(3)??'';
|
||||||
_email = row.colAt(4) ?? '';
|
_email = row.colAt(4)??'';
|
||||||
|
_password = row.colAt(5)??'';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
@ -80,18 +81,18 @@ class _PersonalInfoState extends State<PersonalInfo> {
|
||||||
|
|
||||||
void _saveChanges() async {
|
void _saveChanges() async {
|
||||||
final conn = await MySQLConnection.createConnection(
|
final conn = await MySQLConnection.createConnection(
|
||||||
host: '10.0.2.2',
|
host: '203.64.84.154',
|
||||||
port: 3306,
|
port: 33061,
|
||||||
userName: 'root',
|
userName: 'root',
|
||||||
password: '0000',
|
password: 'Topic@2024',
|
||||||
databaseName: 'testdb',
|
databaseName: 'care',
|
||||||
);
|
);
|
||||||
|
|
||||||
await conn.connect();
|
await conn.connect();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await conn.execute(
|
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},
|
{'email': _emailController.text, 'old_email': widget.email},
|
||||||
);
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
|
|
@ -106,6 +107,7 @@ 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();
|
||||||
|
|
@ -164,13 +166,6 @@ 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),
|
||||||
|
|
@ -179,9 +174,15 @@ class _PersonalInfoState extends State<PersonalInfo> {
|
||||||
),
|
),
|
||||||
Divider(),
|
Divider(),
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text('EMAIL'),
|
title: Text('地址'),
|
||||||
subtitle: //Text(_email),
|
subtitle: Text(_address),
|
||||||
_isEditing
|
//trailing: Icon(Icons.arrow_forward_ios),
|
||||||
|
onTap: () {},
|
||||||
|
),
|
||||||
|
Divider(),
|
||||||
|
ListTile(
|
||||||
|
title: Text('電子信箱'),
|
||||||
|
subtitle: _isEditing
|
||||||
? TextField(
|
? TextField(
|
||||||
controller: _emailController,
|
controller: _emailController,
|
||||||
autofocus: true,
|
autofocus: true,
|
||||||
|
|
@ -193,12 +194,19 @@ class _PersonalInfoState extends State<PersonalInfo> {
|
||||||
)
|
)
|
||||||
: Text(_email),
|
: 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