107 lines
3.8 KiB
Dart
107 lines
3.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
import '../../../core/router/app_router.dart';
|
|
import '../../establishments/data/establishment_repository.dart';
|
|
|
|
/// Écran d'accueil — liste des laveries à proximité.
|
|
class HomeScreen extends ConsumerWidget {
|
|
const HomeScreen({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final establishmentsAsync = ref.watch(establishmentsProvider);
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Laveries'),
|
|
actions: [
|
|
IconButton(
|
|
icon: const Icon(Icons.account_balance_wallet_outlined),
|
|
onPressed: () => context.push(AppRoutes.wallet),
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.person_outline),
|
|
onPressed: () => context.push(AppRoutes.profile),
|
|
),
|
|
],
|
|
),
|
|
body: establishmentsAsync.when(
|
|
loading: () => const Center(child: CircularProgressIndicator()),
|
|
error: (error, _) => Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(24),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
const Icon(Icons.cloud_off, size: 48),
|
|
const SizedBox(height: 12),
|
|
Text(
|
|
'Impossible de charger les laveries.\nVérifiez que l\'API est démarrée.',
|
|
textAlign: TextAlign.center,
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
),
|
|
const SizedBox(height: 16),
|
|
ElevatedButton(
|
|
onPressed: () => ref.invalidate(establishmentsProvider),
|
|
child: const Text('Réessayer'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
data: (establishments) {
|
|
if (establishments.isEmpty) {
|
|
return const Center(child: Text('Aucune laverie disponible'));
|
|
}
|
|
|
|
return RefreshIndicator(
|
|
onRefresh: () async => ref.invalidate(establishmentsProvider),
|
|
child: ListView.separated(
|
|
padding: const EdgeInsets.all(16),
|
|
itemCount: establishments.length,
|
|
separatorBuilder: (_, __) => const SizedBox(height: 8),
|
|
itemBuilder: (context, index) {
|
|
final establishment = establishments[index];
|
|
return Card(
|
|
child: ListTile(
|
|
leading: CircleAvatar(
|
|
child: Text(establishment.name.substring(0, 1)),
|
|
),
|
|
title: Text(establishment.name),
|
|
subtitle: Text(establishment.fullAddress),
|
|
trailing: const Icon(Icons.chevron_right),
|
|
onTap: () => context.push('/establishments/${establishment.uuid}'),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
},
|
|
),
|
|
bottomNavigationBar: NavigationBar(
|
|
selectedIndex: 0,
|
|
onDestinationSelected: (index) {
|
|
switch (index) {
|
|
case 0:
|
|
context.go(AppRoutes.home);
|
|
case 1:
|
|
context.push(AppRoutes.bookings);
|
|
case 2:
|
|
context.push(AppRoutes.washes);
|
|
case 3:
|
|
context.push(AppRoutes.wallet);
|
|
}
|
|
},
|
|
destinations: const [
|
|
NavigationDestination(icon: Icon(Icons.store), label: 'Laveries'),
|
|
NavigationDestination(icon: Icon(Icons.event), label: 'Réservations'),
|
|
NavigationDestination(icon: Icon(Icons.local_laundry_service), label: 'Lavages'),
|
|
NavigationDestination(icon: Icon(Icons.wallet), label: 'Wallet'),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|