114 lines
3.2 KiB
Dart
114 lines
3.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../establishments/data/establishment_repository.dart';
|
|
import '../../establishments/domain/establishment.dart';
|
|
|
|
/// Écran de détail d'un établissement avec liste des machines.
|
|
class EstablishmentDetailScreen extends ConsumerWidget {
|
|
const EstablishmentDetailScreen({
|
|
super.key,
|
|
required this.establishmentUuid,
|
|
});
|
|
|
|
final String establishmentUuid;
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final establishmentAsync =
|
|
ref.watch(establishmentDetailProvider(establishmentUuid));
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('Détail laverie')),
|
|
body: establishmentAsync.when(
|
|
loading: () => const Center(child: CircularProgressIndicator()),
|
|
error: (error, _) => Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Text('Erreur : $error'),
|
|
const SizedBox(height: 12),
|
|
ElevatedButton(
|
|
onPressed: () =>
|
|
ref.invalidate(establishmentDetailProvider(establishmentUuid)),
|
|
child: const Text('Réessayer'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
data: (establishment) => _EstablishmentBody(establishment: establishment),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _EstablishmentBody extends StatelessWidget {
|
|
const _EstablishmentBody({required this.establishment});
|
|
|
|
final Establishment establishment;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ListView(
|
|
padding: const EdgeInsets.all(16),
|
|
children: [
|
|
Text(
|
|
establishment.name,
|
|
style: Theme.of(context).textTheme.headlineSmall,
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(establishment.fullAddress),
|
|
const SizedBox(height: 24),
|
|
Text(
|
|
'Machines (${establishment.machines.length})',
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
),
|
|
const SizedBox(height: 8),
|
|
if (establishment.machines.isEmpty)
|
|
const Text('Aucune machine disponible')
|
|
else
|
|
...establishment.machines.map((machine) => _MachineTile(machine: machine)),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class _MachineTile extends StatelessWidget {
|
|
const _MachineTile({required this.machine});
|
|
|
|
final Machine machine;
|
|
|
|
Color _statusColor(BuildContext context) {
|
|
switch (machine.status) {
|
|
case 'available':
|
|
return Colors.green;
|
|
case 'running':
|
|
return Colors.blue;
|
|
case 'reserved':
|
|
return Colors.orange;
|
|
case 'maintenance':
|
|
case 'offline':
|
|
return Colors.red;
|
|
default:
|
|
return Colors.grey;
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Card(
|
|
child: ListTile(
|
|
leading: Icon(
|
|
machine.type.startsWith('washer') ? Icons.water_drop : Icons.air,
|
|
color: _statusColor(context),
|
|
),
|
|
title: Text(machine.name),
|
|
subtitle: Text('${machine.typeLabel} — ${machine.statusLabel}'),
|
|
trailing: machine.isAvailable
|
|
? const Chip(label: Text('Libre'))
|
|
: null,
|
|
),
|
|
);
|
|
}
|
|
}
|