歷史資料-新增詳細資料頁面

This commit is contained in:
kuei 2024-09-21 13:47:12 +08:00
parent 37ab8411c3
commit 5f4b90e491

View File

@ -23,14 +23,10 @@ class _HistoricalRecordState extends State<HistoricalRecord> {
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',
//127.0.0.1 10.0.2.2
port: 33061, port: 33061,
userName: 'root', userName: 'root',
password: 'Topic@2024', password: 'Topic@2024',
//password: '0000', databaseName: 'care',
databaseName: 'care', //testdb
//databaseName: 'testdb',
); );
await conn.connect(); await conn.connect();
@ -44,13 +40,14 @@ class _HistoricalRecordState extends State<HistoricalRecord> {
} else { } else {
setState(() { setState(() {
_results = result.rows _results = result.rows
.map((row) => { .map((row) =>
'長者ID': row.colAt(0), // {
'姓名': row.colAt(8), '長者ID': row.colAt(4), //
'跌倒時間': row.colAt(1), '姓名': row.colAt(8),
'跌倒原因': row.colAt(2), '跌倒時間': row.colAt(1),
'跌倒地點': row.colAt(7), '跌倒原因': row.colAt(2),
}) '跌倒地點': row.colAt(7),
})
.toList(); .toList();
}); });
} }
@ -81,23 +78,94 @@ class _HistoricalRecordState extends State<HistoricalRecord> {
Expanded( Expanded(
child: ListView.builder( child: 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 ListTile( return Padding(
title: Text(_results[index]['姓名']), padding: const EdgeInsets.symmetric(
subtitle: Text( vertical: 4.0, horizontal: 16.0),
' 長者ID: ${_results[index]['長者ID']},\n ' child:Card(
'跌倒時間: ${_results[index]['跌倒時間']},\n ' elevation: 4, //
'跌倒原因: ${_results[index]['跌倒原因']},\n ' shape: RoundedRectangleBorder(
'跌倒地點: ${_results[index]['跌倒地點']}\n', 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]['姓名'],
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]),
),
);
},
),
),
), ),
); );
}, },
), ),
), ),
SizedBox(height: 70),
], ],
), ),
); );
} }
} }
//
class FallDetailPage extends StatelessWidget {
final Map<String, dynamic> fallDetail;
FallDetailPage({required this.fallDetail});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('${fallDetail['姓名']} 的詳細資料'),
),
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('跌倒時間: ${fallDetail['跌倒時間']}', style: TextStyle(fontSize: 18)),
SizedBox(height: 10),
Text('跌倒原因: ${fallDetail['跌倒原因']}', style: TextStyle(fontSize: 18)),
SizedBox(height: 10),
Text('跌倒地點: ${fallDetail['跌倒地點']}', style: TextStyle(fontSize: 18)),
//
],
),
),
);
}
}