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;
@override
void initState() {
super.initState();
_load();
}
Future<void> _load() async {
setState(() => _loading = true);
final data = await _api.readData();
// afficher les données dans la console pour le débogage
print('Données chargées : $data');
Papa THIAM
a validé
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
setState(() {
_rows = data ?? [];
_loading = false;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Données Google Sheet'),
actions: [
IconButton(
icon: const Icon(Icons.refresh),
onPressed: _load,
)
],
),
body: _loading
? const Center(child: CircularProgressIndicator())
: _rows.isEmpty
? const Center(child: Text('Aucune donnée trouvée'))
: ListView.builder(
itemCount: _rows.length,
itemBuilder: (context, index) {
final row = _rows[index];
return ListTile(
title: Text(row.map((e) => e?.toString() ?? '').join(' | ')),
);
},
),
);
}
}