Integration fonctionnalités V1 ( resas + gestion machines

This commit is contained in:
bastien
2026-07-03 19:02:48 +02:00
parent 20f383dd62
commit bf191d6396
46 changed files with 4691 additions and 654 deletions
+56
View File
@@ -0,0 +1,56 @@
import 'package:flutter/material.dart';
import '../theme/app_colors.dart';
/// État vide avec icône dans un cercle coloré.
class EmptyState extends StatelessWidget {
const EmptyState({
super.key,
required this.icon,
required this.title,
required this.subtitle,
this.iconColor,
this.actionLabel,
this.onAction,
});
final IconData icon;
final String title;
final String subtitle;
final Color? iconColor;
final String? actionLabel;
final VoidCallback? onAction;
@override
Widget build(BuildContext context) {
final color = iconColor ?? AppColors.primary;
return Center(
child: Padding(
padding: const EdgeInsets.all(32),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: 72,
height: 72,
decoration: BoxDecoration(
color: color.withValues(alpha: 0.1),
shape: BoxShape.circle,
),
child: Icon(icon, size: 32, color: color),
),
const SizedBox(height: 16),
Text(title, textAlign: TextAlign.center, style: Theme.of(context).textTheme.titleMedium),
const SizedBox(height: 6),
Text(subtitle, textAlign: TextAlign.center, style: Theme.of(context).textTheme.bodyMedium),
if (actionLabel != null && onAction != null) ...[
const SizedBox(height: 20),
OutlinedButton(onPressed: onAction, child: Text(actionLabel!)),
],
],
),
),
);
}
}
+31
View File
@@ -0,0 +1,31 @@
import 'package:flutter/material.dart';
/// Grille responsive pour les cartes machines (téléphone → tablette).
abstract final class MachineGridLayout {
static const _minTileWidth = 155.0;
static const _maxTileWidth = 190.0;
static SliverGridDelegate delegate(BuildContext context) {
final width = MediaQuery.sizeOf(context).width;
const padding = 32.0;
final available = width - padding;
if (available > _maxTileWidth * 3) {
return const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: _maxTileWidth,
mainAxisSpacing: 10,
crossAxisSpacing: 10,
childAspectRatio: 0.88,
);
}
final count = (available / _minTileWidth).floor().clamp(2, 3);
return SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: count,
mainAxisSpacing: 10,
crossAxisSpacing: 10,
childAspectRatio: count >= 3 ? 0.85 : 0.92,
);
}
}
+450
View File
@@ -0,0 +1,450 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import '../router/app_router.dart';
import '../theme/app_colors.dart';
import '../theme/machine_status_theme.dart';
import '../../features/establishments/domain/establishment.dart';
/// Légende des statuts machines.
class MachineStatusLegend extends StatelessWidget {
const MachineStatusLegend({super.key});
@override
Widget build(BuildContext context) {
return Wrap(
spacing: 12,
runSpacing: 6,
children: [
_LegendDot(color: AppColors.machineAvailable, label: 'Libre'),
_LegendDot(color: AppColors.machineRunning, label: 'En cours'),
_LegendDot(color: AppColors.machineReserved, label: 'Réservée'),
_LegendDot(color: AppColors.machineOffline, label: 'Indisponible'),
],
);
}
}
class _LegendDot extends StatelessWidget {
const _LegendDot({required this.color, required this.label});
final Color color;
final String label;
@override
Widget build(BuildContext context) {
return Row(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 8,
height: 8,
decoration: BoxDecoration(color: color, shape: BoxShape.circle),
),
const SizedBox(width: 5),
Text(label, style: Theme.of(context).textTheme.bodyMedium?.copyWith(fontSize: 12)),
],
);
}
}
/// Carte machine en grille — vue d'ensemble type WashOnline.
class MachineGridCard extends StatelessWidget {
const MachineGridCard({
super.key,
required this.machine,
required this.onTap,
});
final Machine machine;
final VoidCallback onTap;
@override
Widget build(BuildContext context) {
final statusColor = MachineStatusTheme.color(machine.status);
final canStart = MachineStatusTheme.canStart(machine.status);
return Material(
color: AppColors.surface,
elevation: canStart ? 2 : 0,
shadowColor: statusColor.withValues(alpha: 0.2),
borderRadius: BorderRadius.circular(20),
child: InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(20),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: canStart ? statusColor.withValues(alpha: 0.35) : AppColors.divider,
width: canStart ? 1.5 : 1,
),
),
padding: const EdgeInsets.all(10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Container(
width: 36,
height: 36,
decoration: BoxDecoration(
color: statusColor.withValues(alpha: 0.12),
borderRadius: BorderRadius.circular(10),
),
child: Icon(
MachineStatusTheme.iconForType(machine.type),
color: statusColor,
size: 20,
),
),
const Spacer(),
_StatusPill(status: machine.status),
],
),
const SizedBox(height: 10),
Text(
machine.name,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.titleMedium?.copyWith(fontSize: 14),
),
const SizedBox(height: 2),
Text(
machine.typeLabel,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(fontSize: 11),
),
if (canStart) ...[
const Spacer(),
Text(
'Démarrer',
style: TextStyle(
color: statusColor,
fontSize: 11,
fontWeight: FontWeight.w600,
),
),
],
],
),
),
),
);
}
}
class _StatusPill extends StatelessWidget {
const _StatusPill({required this.status});
final String status;
@override
Widget build(BuildContext context) {
final color = MachineStatusTheme.color(status);
return Container(
padding: const EdgeInsets.symmetric(horizontal: 7, vertical: 3),
decoration: BoxDecoration(
color: color.withValues(alpha: 0.12),
borderRadius: BorderRadius.circular(6),
),
child: Text(
MachineStatusTheme.label(status),
style: TextStyle(color: color, fontSize: 10, fontWeight: FontWeight.w700),
),
);
}
}
/// Statistiques rapides du parc machines.
class MachineStatsRow extends StatelessWidget {
const MachineStatsRow({super.key, required this.machines});
final List<Machine> machines;
@override
Widget build(BuildContext context) {
final available = machines.where((m) => m.status == 'available').length;
final running = machines.where((m) => m.status == 'running').length;
final reserved = machines.where((m) => m.status == 'reserved').length;
return Row(
children: [
Expanded(child: _StatBox(value: '$available', label: 'Libres', color: AppColors.machineAvailable)),
const SizedBox(width: 8),
Expanded(child: _StatBox(value: '$running', label: 'En cours', color: AppColors.machineRunning)),
const SizedBox(width: 8),
Expanded(child: _StatBox(value: '$reserved', label: 'Réservées', color: AppColors.machineReserved)),
],
);
}
}
class _StatBox extends StatelessWidget {
const _StatBox({required this.value, required this.label, required this.color});
final String value;
final String label;
final Color color;
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 8),
decoration: BoxDecoration(
color: color.withValues(alpha: 0.08),
borderRadius: BorderRadius.circular(10),
),
child: Column(
children: [
Text(value, style: TextStyle(color: color, fontSize: 20, fontWeight: FontWeight.w700)),
Text(label, style: Theme.of(context).textTheme.bodyMedium?.copyWith(fontSize: 11)),
],
),
);
}
}
/// Actions rapides — démarrage en quelques clics.
class QuickActionsRow extends StatelessWidget {
const QuickActionsRow({super.key});
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
child: _QuickAction(
icon: Icons.qr_code_scanner_rounded,
label: 'Scanner',
color: AppColors.primary,
onTap: () => context.push(AppRoutes.washScan),
),
),
const SizedBox(width: 10),
Expanded(
child: _QuickAction(
icon: Icons.event_available_outlined,
label: 'Réserver',
color: AppColors.machineReserved,
onTap: () => context.go(AppRoutes.bookings),
),
),
const SizedBox(width: 10),
Expanded(
child: _QuickAction(
icon: Icons.add_card_outlined,
label: 'Recharger',
color: AppColors.secondary,
onTap: () => context.go(AppRoutes.wallet),
),
),
],
);
}
}
class _QuickAction extends StatelessWidget {
const _QuickAction({
required this.icon,
required this.label,
required this.color,
required this.onTap,
});
final IconData icon;
final String label;
final Color color;
final VoidCallback onTap;
@override
Widget build(BuildContext context) {
return Material(
color: AppColors.surface,
elevation: 1,
shadowColor: Colors.black.withValues(alpha: 0.06),
borderRadius: BorderRadius.circular(12),
child: InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(12),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 14),
child: Column(
children: [
Icon(icon, color: color, size: 26),
const SizedBox(height: 6),
Text(label, style: const TextStyle(fontSize: 12, fontWeight: FontWeight.w600)),
],
),
),
),
);
}
}
/// Bannière lavage en cours.
class ActiveWashBanner extends StatelessWidget {
const ActiveWashBanner({
super.key,
required this.machineName,
required this.onTap,
});
final String machineName;
final VoidCallback onTap;
@override
Widget build(BuildContext context) {
return Material(
color: AppColors.primary,
borderRadius: BorderRadius.circular(14),
elevation: 2,
child: InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(14),
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(
children: [
Container(
width: 44,
height: 44,
decoration: BoxDecoration(
color: Colors.white.withValues(alpha: 0.2),
borderRadius: BorderRadius.circular(12),
),
child: const Icon(Icons.local_laundry_service, color: Colors.white),
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Lavage en cours',
style: TextStyle(color: Colors.white70, fontSize: 12),
),
Text(
machineName,
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 16,
),
),
],
),
),
const Icon(Icons.chevron_right, color: Colors.white),
],
),
),
),
);
}
}
/// Bottom sheet détail machine + actions.
class MachineActionSheet {
static Future<void> show(
BuildContext context, {
required Machine machine,
required VoidCallback onStart,
VoidCallback? onReserve,
}) {
final statusColor = MachineStatusTheme.color(machine.status);
final canStart = MachineStatusTheme.canStart(machine.status);
return showModalBottomSheet<void>(
context: context,
isScrollControlled: true,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
),
builder: (context) => Padding(
padding: EdgeInsets.fromLTRB(20, 16, 20, 20 + MediaQuery.of(context).padding.bottom),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Center(
child: Container(
width: 40,
height: 4,
decoration: BoxDecoration(
color: AppColors.divider,
borderRadius: BorderRadius.circular(2),
),
),
),
const SizedBox(height: 20),
Row(
children: [
Container(
width: 52,
height: 52,
decoration: BoxDecoration(
color: statusColor.withValues(alpha: 0.12),
borderRadius: BorderRadius.circular(14),
),
child: Icon(
MachineStatusTheme.iconForType(machine.type),
color: statusColor,
size: 28,
),
),
const SizedBox(width: 14),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(machine.name, style: Theme.of(context).textTheme.titleMedium),
Text(machine.typeLabel, style: Theme.of(context).textTheme.bodyMedium),
],
),
),
_StatusPill(status: machine.status),
],
),
const SizedBox(height: 20),
if (canStart) ...[
ElevatedButton.icon(
onPressed: () {
Navigator.pop(context);
onStart();
},
icon: const Icon(Icons.play_arrow_rounded),
label: const Text('Démarrer maintenant'),
),
const SizedBox(height: 10),
OutlinedButton.icon(
onPressed: () {
Navigator.pop(context);
onReserve?.call();
},
icon: const Icon(Icons.event_outlined),
label: const Text('Réserver un créneau'),
),
] else
Container(
padding: const EdgeInsets.all(14),
decoration: BoxDecoration(
color: statusColor.withValues(alpha: 0.08),
borderRadius: BorderRadius.circular(12),
),
child: Text(
machine.status == 'running'
? 'Cette machine est en cours d\'utilisation.'
: machine.status == 'reserved'
? 'Machine réservée — elle sera disponible sur votre créneau.'
: 'Machine indisponible pour le moment.',
textAlign: TextAlign.center,
style: TextStyle(color: statusColor, fontWeight: FontWeight.w500),
),
),
],
),
),
);
}
}
+104
View File
@@ -0,0 +1,104 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import '../router/app_router.dart';
import '../theme/app_colors.dart';
import 'wallet_chip.dart';
/// Coque principale — navigation + solde visible (style WashOnline amélioré).
class MainShell extends ConsumerWidget {
const MainShell({super.key, required this.child});
final Widget child;
static int _indexFromLocation(String location) {
if (location.startsWith(AppRoutes.bookings)) return 1;
if (location.startsWith(AppRoutes.washes)) return 2;
if (location.startsWith(AppRoutes.wallet)) return 3;
if (location.startsWith(AppRoutes.profile)) return 4;
return 0;
}
static String _titleFromLocation(String location) {
if (location.startsWith(AppRoutes.bookings)) return 'Réservations';
if (location.startsWith(AppRoutes.washes)) return 'Mes lavages';
if (location.startsWith(AppRoutes.wallet)) return 'Portefeuille';
if (location.startsWith(AppRoutes.profile)) return 'Mon profil';
return 'Accueil';
}
static bool _showScanFab(String location) {
return location.startsWith(AppRoutes.bookings) ||
location.startsWith(AppRoutes.washes);
}
void _onTabTap(BuildContext context, int index) {
switch (index) {
case 0:
context.go(AppRoutes.home);
case 1:
context.go(AppRoutes.bookings);
case 2:
context.go(AppRoutes.washes);
case 3:
context.go(AppRoutes.wallet);
case 4:
context.go(AppRoutes.profile);
}
}
@override
Widget build(BuildContext context, WidgetRef ref) {
final location = GoRouterState.of(context).uri.toString();
final selectedIndex = _indexFromLocation(location);
final showScanFab = _showScanFab(location);
return Scaffold(
backgroundColor: AppColors.background,
appBar: AppBar(
title: Text(_titleFromLocation(location)),
actions: const [WalletChip()],
),
body: child,
floatingActionButton: showScanFab
? FloatingActionButton.extended(
onPressed: () => context.push(AppRoutes.washScan),
icon: const Icon(Icons.qr_code_scanner_rounded),
label: const Text('Scanner'),
)
: null,
bottomNavigationBar: NavigationBar(
selectedIndex: selectedIndex,
onDestinationSelected: (index) => _onTabTap(context, index),
destinations: const [
NavigationDestination(
icon: Icon(Icons.home_outlined),
selectedIcon: Icon(Icons.home_rounded),
label: 'Accueil',
),
NavigationDestination(
icon: Icon(Icons.event_outlined),
selectedIcon: Icon(Icons.event),
label: 'Résa',
),
NavigationDestination(
icon: Icon(Icons.local_laundry_service_outlined),
selectedIcon: Icon(Icons.local_laundry_service),
label: 'Lavages',
),
NavigationDestination(
icon: Icon(Icons.account_balance_wallet_outlined),
selectedIcon: Icon(Icons.account_balance_wallet),
label: 'Wallet',
),
NavigationDestination(
icon: Icon(Icons.person_outline),
selectedIcon: Icon(Icons.person),
label: 'Profil',
),
],
),
);
}
}
+92
View File
@@ -0,0 +1,92 @@
import 'package:flutter/material.dart';
import '../theme/app_colors.dart';
/// Badge de statut discret.
class StatusBadge extends StatelessWidget {
const StatusBadge({super.key, required this.label, required this.color});
final String label;
final Color color;
factory StatusBadge.fromStatus(String status) {
final (label, color) = switch (status) {
'available' || 'confirmed' || 'completed' => ('Disponible', AppColors.machineAvailable),
'running' || 'active' || 'pending_start' => ('En cours', AppColors.machineRunning),
'reserved' || 'pending' => ('Réservé', AppColors.machineReserved),
'cancelled' => ('Annulé', AppColors.textSecondary),
_ => (status, AppColors.textSecondary),
};
return StatusBadge(label: label, color: color);
}
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
decoration: BoxDecoration(
color: color.withValues(alpha: 0.12),
borderRadius: BorderRadius.circular(6),
),
child: Text(
label,
style: TextStyle(color: color, fontSize: 11, fontWeight: FontWeight.w600),
),
);
}
}
/// Bandeau d'en-tête discret pour les écrans principaux.
class ScreenHeader extends StatelessWidget {
const ScreenHeader({
super.key,
required this.title,
this.subtitle,
});
final String title;
final String? subtitle;
@override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
margin: const EdgeInsets.fromLTRB(16, 8, 16, 12),
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
gradient: AppColors.gradientAccent,
borderRadius: BorderRadius.circular(14),
boxShadow: [
BoxShadow(
color: AppColors.primary.withValues(alpha: 0.15),
blurRadius: 8,
offset: const Offset(0, 3),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: const TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.w600,
),
),
if (subtitle != null) ...[
const SizedBox(height: 4),
Text(
subtitle!,
style: TextStyle(
color: Colors.white.withValues(alpha: 0.9),
fontSize: 13,
),
),
],
],
),
);
}
}
+74
View File
@@ -0,0 +1,74 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:intl/intl.dart';
import '../router/app_router.dart';
import '../theme/app_colors.dart';
import '../../features/wallet/data/wallet_repository.dart';
/// Solde portefeuille compact — toujours visible (comme WashOnline).
class WalletChip extends ConsumerWidget {
const WalletChip({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final walletAsync = ref.watch(walletProvider);
final format = NumberFormat.currency(locale: 'fr_FR', symbol: '', decimalDigits: 2);
return walletAsync.when(
loading: () => const Padding(
padding: EdgeInsets.only(right: 12),
child: SizedBox(width: 18, height: 18, child: CircularProgressIndicator(strokeWidth: 2)),
),
error: (_, __) => _ChipButton(
label: '— €',
onTap: () => context.go(AppRoutes.wallet),
),
data: (wallet) => _ChipButton(
label: format.format(wallet.currentBalance),
onTap: () => context.go(AppRoutes.wallet),
),
);
}
}
class _ChipButton extends StatelessWidget {
const _ChipButton({required this.label, required this.onTap});
final String label;
final VoidCallback onTap;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(right: 8),
child: Material(
color: AppColors.primary.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(20),
child: InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(20),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.account_balance_wallet_outlined, size: 16, color: AppColors.primary),
const SizedBox(width: 6),
Text(
label,
style: const TextStyle(
color: AppColors.primary,
fontWeight: FontWeight.w700,
fontSize: 13,
),
),
],
),
),
),
),
);
}
}