跌倒紀錄編號更新

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:better_player_plus/better_player_plus.dart';
class HistoricalRecord extends StatefulWidget {
final String email; // 接收來自上個頁面的 email
HistoricalRecord({required this.email});
@@ -14,6 +13,7 @@ class HistoricalRecord extends StatefulWidget {
class _HistoricalRecordState extends State<HistoricalRecord> {
List<Map<String, dynamic>> _results = [];
int _totalRecords = 0; // 儲存總比數
@override
void initState() {
@@ -34,44 +34,50 @@ class _HistoricalRecordState extends State<HistoricalRecord> {
await conn.connect();
try {
var userNameResult = await conn.execute(// 使用傳遞過來的 email來找homeusername
var userNameResult = await conn.execute(
'SELECT homeUserName FROM HomeLogin WHERE homeEmail = :email',
{'email': widget.email},
);
if (userNameResult.rows.isNotEmpty) {
String homeUserName = userNameResult.rows.first.colByName(
"homeUserName").toString();
String homeUserName = userNameResult.rows.first.colByName("homeUserName").toString();
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(
'SELECT HomeElderFall.* FROM HomeElderFall WHERE homeUserName = :homeUserName ORDER BY hfTime DESC',
{'homeUserName': homeUserName},
);
if (fallResult.rows.isEmpty) {
print('No data found in users table.');
if (fallResult.rows.isEmpty) {
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 {
setState(() {
_results = fallResult.rows
.map((row) =>
{
//'長者ID': row.colAt(4), //去裝資料庫的行數
'跌倒編號': row.colAt(0), // 跌倒紀錄的編號 hfId
//'姓名': row.colAt(8),
'跌倒時間': row.colAt(1),
'跌倒原因': row.colAt(2),
'跌倒地點': row.colAt(6),
})
.toList();
_results = [];
});
print('No data found.');
}
}else {
setState(() {
_results = [];
});
print('No data found.');
}
} catch (e) {
print('Error: $e');
} finally {
@@ -99,67 +105,67 @@ class _HistoricalRecordState extends State<HistoricalRecord> {
Expanded(
child: _results.isEmpty
? Center(
child: Text(
'尚無跌倒紀錄', // 當沒有資料時顯示的訊息
style: TextStyle(fontSize: 20, color: Colors.grey),
),
)
child: Text(
'尚無跌倒紀錄', // 當沒有資料時顯示的訊息
style: TextStyle(fontSize: 20, color: Colors.grey),
),
)
: ListView.builder(
padding: EdgeInsets.symmetric(vertical: 5), // 整列表视图的 padding
itemCount: _results.length,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.symmetric(
vertical: 4.0, horizontal: 16.0),
child:Card(
elevation: 4, // 卡片陰影效果
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0), // 圓角卡片
),
child: Container(
decoration: BoxDecoration(
border: Border(
left: BorderSide(color: Color(0xFFFFCC99), width: 5.0), // 左邊框
top: BorderSide(color: Color(0xFFFFCC99), width: 5.0), // 邊框
),
borderRadius: BorderRadius.circular(10.0), // 圓角
),
child: ListTile(
title: Text(
'紀錄編號: ${_results[index]['跌倒編號']}', // 顯示 hfId
//_results[index]['姓名'],
style: TextStyle(
fontWeight: FontWeight.bold,
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]),
),
);
},
),
padding: EdgeInsets.symmetric(vertical: 5), // 調整列表視圖的 padding
itemCount: _results.length,
itemBuilder: (context, index) {
int displayIndex = _totalRecords - index; // 計算倒序編號
return Padding(
padding: const EdgeInsets.symmetric(
vertical: 4.0, horizontal: 16.0),
child:Card(
elevation: 4, // 卡片陰影效果
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0), // 圓角卡片
),
child: Container(
decoration: BoxDecoration(
border: Border(
left: BorderSide(color: Color(0xFFFFCC99), width: 5.0), // 邊框
top: BorderSide(color: Color(0xFFFFCC99), width: 5.0), // 上邊框
),
borderRadius: BorderRadius.circular(10.0), // 圓角
),
child: ListTile(
title: Text(
'紀錄編號: 第${displayIndex}', // 使用倒序顯示編號
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
);
},
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),
],
@@ -186,10 +192,10 @@ class _FallDetailPageState extends State<FallDetailPage> {
void initState() {
super.initState();
BetterPlayerConfiguration betterPlayerConfiguration =
const BetterPlayerConfiguration(
aspectRatio: 16 / 9,
fit: BoxFit.contain,
);
const BetterPlayerConfiguration(
aspectRatio: 16 / 9,
fit: BoxFit.contain,
);
_betterPlayerController = BetterPlayerController(betterPlayerConfiguration);
_fetchData(); // 連資料庫、取得影片連結
@@ -239,21 +245,18 @@ class _FallDetailPageState extends State<FallDetailPage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('詳細資料'),//'${fallDetail['姓名']} 的詳細資料'
title: Text('詳細資料'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
//Text('長者ID: ${fallDetail['長者ID']}', style: TextStyle(fontSize: 18)),
//SizedBox(height: 10),
Text('跌倒時間: ${widget.fallDetail['跌倒時間']}', style: TextStyle(fontSize: 18)),
SizedBox(height: 10),
Text('跌倒原因: ${widget.fallDetail['跌倒原因']}', style: TextStyle(fontSize: 18)),
SizedBox(height: 10),
Text('跌倒地點: ${widget.fallDetail['跌倒地點']}', style: TextStyle(fontSize: 18)),
// 在這裡可以添加更多詳細資料
if (fhvideoId != '') AspectRatio(
aspectRatio: 16 / 9,
child: BetterPlayer(controller: _betterPlayerController),
@@ -263,4 +266,4 @@ class _FallDetailPageState extends State<FallDetailPage> {
),
);
}
}
}