Newer
Older
Papa THIAM
a validé
import 'package:flutter/material.dart';
import 'google_sheets_api.dart';
class SheetViewPage extends StatefulWidget {
const SheetViewPage({super.key});
@override
State<SheetViewPage> createState() => _SheetViewPageState();
}
class _SheetViewPageState extends State<SheetViewPage> {
final GoogleSheetsApi _api = GoogleSheetsApi();
List<List<dynamic>> _rows = [];
bool _loading = false;
final Color _primaryColor = const Color(0xFF4361EE);
Papa THIAM
a validé
@override
void initState() {
super.initState();
_load();
}
Future<void> _load() async {
setState(() => _loading = true);
final data = await _api.readData();
print('Données chargées : $data');
Papa THIAM
a validé
setState(() {
_rows = data ?? [];
_loading = false;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
Papa THIAM
a validé
appBar: AppBar(
title: const Text(
'Liste des Étudiants',
style: TextStyle(fontWeight: FontWeight.bold),
),
backgroundColor: _primaryColor,
foregroundColor: Colors.white,
elevation: 0,
Papa THIAM
a validé
actions: [
IconButton(
Papa THIAM
a validé
onPressed: _load,
Papa THIAM
a validé
)
],
),
body: _loading
? const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(),
SizedBox(height: 16),
Text(
'Chargement des données...',
style: TextStyle(fontSize: 16, color: Colors.grey),
),
],
),
)
Papa THIAM
a validé
: _rows.isEmpty
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
? Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.table_chart_outlined,
size: 80,
color: Colors.grey.shade300,
),
const SizedBox(height: 16),
const Text(
'Aucune donnée trouvée',
style: TextStyle(fontSize: 18, color: Colors.grey),
),
const SizedBox(height: 8),
Text(
'Les données apparaitront ici après inscription',
style: TextStyle(fontSize: 14, color: Colors.grey.shade500),
textAlign: TextAlign.center,
),
],
),
)
: Padding(
padding: const EdgeInsets.all(16),
child: Card(
elevation: 4,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
child: Column(
children: [
// En-tête du tableau
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: _primaryColor.withOpacity(0.1),
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(16),
topRight: Radius.circular(16),
),
),
child: Row(
children: [
Icon(Icons.table_chart_rounded, color: _primaryColor),
const SizedBox(width: 12),
Text(
'${_rows.length} étudiant(s) inscrit(s)',
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
const Spacer(),
Chip(
label: Text('${_rows.length} éléments'),
backgroundColor: _primaryColor,
labelStyle: const TextStyle(color: Colors.white),
),
],
),
),
// Liste des données
Expanded(
child: ListView.separated(
Papa THIAM
a validé
itemCount: _rows.length,
separatorBuilder: (context, index) => Divider(
height: 1,
color: Colors.grey.shade200,
),
Papa THIAM
a validé
itemBuilder: (context, index) {
final row = _rows[index];
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
return Container(
decoration: BoxDecoration(
color: index.isEven
? Colors.white
: Colors.grey.withOpacity(0.02),
),
child: ListTile(
leading: Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: _primaryColor.withOpacity(0.1),
shape: BoxShape.circle,
),
child: Icon(
Icons.person_rounded,
color: _primaryColor,
size: 20,
),
),
title: Text(
'${row.length > 1 ? '${row[1]} ${row[2]}' : 'Étudiant ${index + 1}'}',
style: const TextStyle(
fontWeight: FontWeight.w500,
),
),
subtitle: row.length > 0
? Text(
'N°: ${row[0]?.toString() ?? 'N/A'}',
style: TextStyle(
color: Colors.grey.shade600,
),
)
: null,
trailing: Icon(
Icons.chevron_right_rounded,
color: Colors.grey.shade400,
),
onTap: () {
// Optionnel: Ajouter une vue détaillée
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Détails de l\'étudiant'),
content: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: row.asMap().entries.map((entry) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
child: Text(
'${_getColumnName(entry.key)}: ${entry.value?.toString() ?? 'N/A'}',
),
);
}).toList(),
),
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('Fermer'),
),
],
),
);
},
),
Papa THIAM
a validé
);
},
),
Papa THIAM
a validé
);
}
String _getColumnName(int index) {
const columns = [
'Numéro étudiant',
'Prénom',
'Nom',
'MAC',
'NFC',
'QR Code',
'Date d\'inscription'
];
return index < columns.length ? columns[index] : 'Colonne $index';
}
}