-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_report_generator.dart
83 lines (72 loc) · 2.53 KB
/
admin_report_generator.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
class ReportScreen extends StatefulWidget {
@override
_ReportScreenState createState() => _ReportScreenState();
}
class _ReportScreenState extends State<ReportScreen> {
final FirebaseAuth _auth = FirebaseAuth.instance;
final FirebaseFirestore _firestore = FirebaseFirestore.instance;
bool _isLoading = false;
String _errorMessage = '';
@override
void initState() {
super.initState();
_fetchReportsData();
}
Future<void> _fetchReportsData() async {
setState(() {
_isLoading = true;
});
try {
// Fetch data from Firestore collections
final QuerySnapshot volunteersSnapshot = await _firestore.collection('volunteers').get();
final QuerySnapshot activitiesSnapshot = await _firestore.collection('activities').get();
final QuerySnapshot certificatesSnapshot = await _firestore.collection('certificates').get();
// Process fetched data as needed
final List<Map<String, dynamic>> volunteers = volunteersSnapshot.docs.map((doc) => doc.data()).toList();
final List<Map<String, dynamic>> activities = activitiesSnapshot.docs.map((doc) => doc.data()).toList();
final List<Map<String, dynamic>> certificates = certificatesSnapshot.docs.map((doc) => doc.data()).toList();
// Update other data states as needed
setState(() {
// Example: Print fetched data
print('Volunteers data: $volunteers');
print('Activities data: $activities');
print('Certificates data: $certificates');
_isLoading = false;
});
} catch (error) {
setState(() {
_isLoading = false;
_errorMessage = 'Failed to load report data. Please try again later.';
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Reports'),
),
body: _isLoading
? Center(child: CircularProgressIndicator())
: _errorMessage.isNotEmpty
? Center(child: Text(_errorMessage))
: SingleChildScrollView(
padding: EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Data Report on Volunteers'),
],
),
),
);
}
}
void main() {
runApp(MaterialApp(
home: ReportScreen(),
));
}