Compare commits

..

No commits in common. "d2a2030979714e7d5ff606d097f0af7634cf09f6" and "10d856208d678d7e071b13534d6c5dab6e4fe17f" have entirely different histories.

4 changed files with 130 additions and 224 deletions

View File

@ -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,11 +51,13 @@ 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']}',
), ),
); );
}, },

View File

@ -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(

View File

@ -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,167 +11,85 @@ 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),
),*/
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: Stack(children: [ child: Center(
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: GridView.count( child: ListView.builder(
crossAxisCount: 2, padding: EdgeInsets.symmetric(vertical: 5), // padding
shrinkWrap: true, itemCount: _results.length, //
physics: NeverScrollableScrollPhysics(), itemBuilder: (context, index) {
padding: EdgeInsets.all(16), final user = _results[index];
children: [ return ListTile(
_buildGridItem(Icons.monitor_outlined, '畫面1', context), title: Text(user['name']), //
_buildGridItem(Icons.monitor_outlined, '畫面2', context), subtitle: Text('gender: ${user['gender']}'), //
/*_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)),
], ],
), ),
),
),
); );
} }
} }

View File

@ -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,7 +51,7 @@ 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) {
@ -60,10 +60,9 @@ class _PersonalInfoState extends State<PersonalInfo> {
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,15 +179,9 @@ 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: () {},
),
Divider(),
ListTile(
title: Text('電子信箱'),
subtitle: _isEditing
? TextField( ? TextField(
controller: _emailController, controller: _emailController,
autofocus: true, autofocus: true,
@ -194,19 +193,12 @@ 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,