HistoryScreen
HistoryScreen
dart';
import 'package:cloud_firestore/cloud_firestore.dart';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Recognition History"),
),
body: StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance
.collection('recognition_history')
.orderBy('timestamp', descending: true)
.snapshots(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
}
if (!snapshot.hasData || snapshot.data!.docs.isEmpty) {
return const Center(child: Text("No recognition history found."));
}
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: DataTable(
columns: const [
DataColumn(label: Text('Name')),
DataColumn(label: Text('Timestamp')),
],
rows: records.map((doc) {
final data = doc.data() as Map<String, dynamic>;
final name = data['name'] as String;
final timestamp = (data['timestamp'] as Timestamp).toDate();
return DataRow(cells: [
DataCell(Text(name)),
DataCell(Text(timestamp.toString())),
]);
}).toList(),
),
);
},
),
);
}
}