跌倒紀錄編號更新

This commit is contained in:
kuei 2024-10-31 01:19:51 +08:00
parent c7cce038aa
commit fbe67b7dd9

View File

@ -3,7 +3,6 @@ import 'package:mysql_client/mysql_client.dart';
import 'package:video_player/video_player.dart'; import 'package:video_player/video_player.dart';
import 'package:better_player_plus/better_player_plus.dart'; import 'package:better_player_plus/better_player_plus.dart';
class HistoricalRecord extends StatefulWidget { class HistoricalRecord extends StatefulWidget {
final String email; // email final String email; // email
HistoricalRecord({required this.email}); HistoricalRecord({required this.email});
@ -14,6 +13,7 @@ class HistoricalRecord extends StatefulWidget {
class _HistoricalRecordState extends State<HistoricalRecord> { class _HistoricalRecordState extends State<HistoricalRecord> {
List<Map<String, dynamic>> _results = []; List<Map<String, dynamic>> _results = [];
int _totalRecords = 0; //
@override @override
void initState() { void initState() {
@ -34,44 +34,50 @@ class _HistoricalRecordState extends State<HistoricalRecord> {
await conn.connect(); await conn.connect();
try { try {
var userNameResult = await conn.execute(// 使 email來找homeusername var userNameResult = await conn.execute(
'SELECT homeUserName FROM HomeLogin WHERE homeEmail = :email', 'SELECT homeUserName FROM HomeLogin WHERE homeEmail = :email',
{'email': widget.email}, {'email': widget.email},
); );
if (userNameResult.rows.isNotEmpty) { if (userNameResult.rows.isNotEmpty) {
String homeUserName = userNameResult.rows.first.colByName( String homeUserName = userNameResult.rows.first.colByName("homeUserName").toString();
"homeUserName").toString();
print('homeUserName: $homeUserName'); print('homeUserName: $homeUserName');
// homeUserName
//
var countResult = await conn.execute(
'SELECT COUNT(*) AS total FROM HomeElderFall WHERE homeUserName = :homeUserName',
{'homeUserName': homeUserName},
);
if (countResult.rows.isNotEmpty) {
_totalRecords = int.parse(countResult.rows.first.colByName("total").toString());
}
// homeUserName
var fallResult = await conn.execute( var fallResult = await conn.execute(
'SELECT HomeElderFall.* FROM HomeElderFall WHERE homeUserName = :homeUserName ORDER BY hfTime DESC', 'SELECT HomeElderFall.* FROM HomeElderFall WHERE homeUserName = :homeUserName ORDER BY hfTime DESC',
{'homeUserName': homeUserName}, {'homeUserName': homeUserName},
); );
if (fallResult.rows.isEmpty) {
if (fallResult.rows.isEmpty) { print('No data found in users table.');
print('No data found in users table.'); } else {
setState(() {
_results = fallResult.rows
.map((row) =>
{
'跌倒時間': row.colAt(1),
'跌倒原因': row.colAt(2),
'跌倒地點': row.colAt(6),
})
.toList();
});
}
} else { } else {
setState(() { setState(() {
_results = fallResult.rows _results = [];
.map((row) =>
{
//'長者ID': row.colAt(4), //
'跌倒編號': row.colAt(0), // hfId
//'姓名': row.colAt(8),
'跌倒時間': row.colAt(1),
'跌倒原因': row.colAt(2),
'跌倒地點': row.colAt(6),
})
.toList();
}); });
print('No data found.');
} }
}else {
setState(() {
_results = [];
});
print('No data found.');
}
} catch (e) { } catch (e) {
print('Error: $e'); print('Error: $e');
} finally { } finally {
@ -99,67 +105,67 @@ class _HistoricalRecordState extends State<HistoricalRecord> {
Expanded( Expanded(
child: _results.isEmpty child: _results.isEmpty
? Center( ? Center(
child: Text( child: Text(
'尚無跌倒紀錄', // '尚無跌倒紀錄', //
style: TextStyle(fontSize: 20, color: Colors.grey), style: TextStyle(fontSize: 20, color: Colors.grey),
), ),
) )
: ListView.builder( : ListView.builder(
padding: EdgeInsets.symmetric(vertical: 5), // padding padding: EdgeInsets.symmetric(vertical: 5), // 調 padding
itemCount: _results.length, itemCount: _results.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
return Padding( int displayIndex = _totalRecords - index; //
padding: const EdgeInsets.symmetric( return Padding(
vertical: 4.0, horizontal: 16.0), padding: const EdgeInsets.symmetric(
child:Card( vertical: 4.0, horizontal: 16.0),
elevation: 4, // child:Card(
shape: RoundedRectangleBorder( elevation: 4, //
borderRadius: BorderRadius.circular(10.0), // shape: RoundedRectangleBorder(
), borderRadius: BorderRadius.circular(10.0), //
child: Container( ),
decoration: BoxDecoration( child: Container(
border: Border( decoration: BoxDecoration(
left: BorderSide(color: Color(0xFFFFCC99), width: 5.0), // border: Border(
top: BorderSide(color: Color(0xFFFFCC99), width: 5.0), // left: BorderSide(color: Color(0xFFFFCC99), width: 5.0), //
), top: BorderSide(color: Color(0xFFFFCC99), width: 5.0), //
borderRadius: BorderRadius.circular(10.0), // ),
), borderRadius: BorderRadius.circular(10.0), //
child: ListTile( ),
title: Text( child: ListTile(
'紀錄編號: ${_results[index]['跌倒編號']}', // hfId title: Text(
//_results[index]['姓名'], '紀錄編號: 第${displayIndex}', // 使
style: TextStyle( style: TextStyle(
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: 18, fontSize: 18,
),
),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(//'長者ID: ${_results[index]['長者ID']}\n'
'跌倒時間: ${_results[index]['跌倒時間']}\n'
'跌倒原因: ${_results[index]['跌倒原因']}\n'
'跌倒地點: ${_results[index]['跌倒地點']}\n',
style: TextStyle(fontSize: 16, color: Colors.black), //
),
],
),
onTap: () {
//
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
FallDetailPage(fallDetail: _results[index]),
),
);
},
),
), ),
), ),
); subtitle: Column(
}, crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'跌倒時間: ${_results[index]['跌倒時間']}\n'
'跌倒原因: ${_results[index]['跌倒原因']}\n'
'跌倒地點: ${_results[index]['跌倒地點']}\n',
style: TextStyle(fontSize: 16, color: Colors.black), //
),
],
),
onTap: () {
//
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
FallDetailPage(fallDetail: _results[index]),
),
);
},
),
),
), ),
);
},
),
), ),
SizedBox(height: 60), SizedBox(height: 60),
], ],
@ -186,10 +192,10 @@ class _FallDetailPageState extends State<FallDetailPage> {
void initState() { void initState() {
super.initState(); super.initState();
BetterPlayerConfiguration betterPlayerConfiguration = BetterPlayerConfiguration betterPlayerConfiguration =
const BetterPlayerConfiguration( const BetterPlayerConfiguration(
aspectRatio: 16 / 9, aspectRatio: 16 / 9,
fit: BoxFit.contain, fit: BoxFit.contain,
); );
_betterPlayerController = BetterPlayerController(betterPlayerConfiguration); _betterPlayerController = BetterPlayerController(betterPlayerConfiguration);
_fetchData(); // _fetchData(); //
@ -239,21 +245,18 @@ class _FallDetailPageState extends State<FallDetailPage> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text('詳細資料'),//'${fallDetail['姓名']} 的詳細資料' title: Text('詳細資料'),
), ),
body: Padding( body: Padding(
padding: const EdgeInsets.all(16.0), padding: const EdgeInsets.all(16.0),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
//Text('長者ID: ${fallDetail['長者ID']}', style: TextStyle(fontSize: 18)),
//SizedBox(height: 10),
Text('跌倒時間: ${widget.fallDetail['跌倒時間']}', style: TextStyle(fontSize: 18)), Text('跌倒時間: ${widget.fallDetail['跌倒時間']}', style: TextStyle(fontSize: 18)),
SizedBox(height: 10), SizedBox(height: 10),
Text('跌倒原因: ${widget.fallDetail['跌倒原因']}', style: TextStyle(fontSize: 18)), Text('跌倒原因: ${widget.fallDetail['跌倒原因']}', style: TextStyle(fontSize: 18)),
SizedBox(height: 10), SizedBox(height: 10),
Text('跌倒地點: ${widget.fallDetail['跌倒地點']}', style: TextStyle(fontSize: 18)), Text('跌倒地點: ${widget.fallDetail['跌倒地點']}', style: TextStyle(fontSize: 18)),
//
if (fhvideoId != '') AspectRatio( if (fhvideoId != '') AspectRatio(
aspectRatio: 16 / 9, aspectRatio: 16 / 9,
child: BetterPlayer(controller: _betterPlayerController), child: BetterPlayer(controller: _betterPlayerController),
@ -263,4 +266,4 @@ class _FallDetailPageState extends State<FallDetailPage> {
), ),
); );
} }
} }