0% found this document useful (0 votes)
6 views

HistoryScreen

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

HistoryScreen

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import 'package:flutter/material.

dart';
import 'package:cloud_firestore/cloud_firestore.dart';

class HistoryScreen extends StatelessWidget {


const HistoryScreen({Key? key}) : super(key: key);

@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."));
}

final records = snapshot.data!.docs;

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(),
),
);
},
),
);
}
}

You might also like