Integration fonctionnalités V1 ( resas + gestion machines
This commit is contained in:
@@ -9,7 +9,8 @@ class ApiClient {
|
||||
ApiClient({
|
||||
required this.baseUrl,
|
||||
this.getAccessToken,
|
||||
this.onUnauthorized,
|
||||
this.onRefreshToken,
|
||||
this.onSessionExpired,
|
||||
}) : _dio = Dio(
|
||||
BaseOptions(
|
||||
baseUrl: baseUrl,
|
||||
@@ -31,9 +32,27 @@ class ApiClient {
|
||||
handler.next(options);
|
||||
},
|
||||
onError: (error, handler) async {
|
||||
if (error.response?.statusCode == 401) {
|
||||
await onUnauthorized?.call();
|
||||
final response = error.response;
|
||||
final alreadyRetried = error.requestOptions.extra['auth_retried'] == true;
|
||||
|
||||
if (response?.statusCode == 401 && !alreadyRetried && onRefreshToken != null) {
|
||||
final newToken = await onRefreshToken!();
|
||||
if (newToken != null && newToken.isNotEmpty) {
|
||||
final request = error.requestOptions;
|
||||
request.extra['auth_retried'] = true;
|
||||
request.headers['Authorization'] = 'Bearer $newToken';
|
||||
|
||||
try {
|
||||
final retryResponse = await _dio.fetch(request);
|
||||
return handler.resolve(retryResponse);
|
||||
} on DioException catch (retryError) {
|
||||
return handler.next(retryError);
|
||||
}
|
||||
}
|
||||
|
||||
await onSessionExpired?.call();
|
||||
}
|
||||
|
||||
handler.next(error);
|
||||
},
|
||||
),
|
||||
@@ -42,7 +61,8 @@ class ApiClient {
|
||||
|
||||
final String baseUrl;
|
||||
final Future<String?> Function()? getAccessToken;
|
||||
final Future<void> Function()? onUnauthorized;
|
||||
final Future<String?> Function()? onRefreshToken;
|
||||
final Future<void> Function()? onSessionExpired;
|
||||
final Dio _dio;
|
||||
|
||||
Dio get dio => _dio;
|
||||
@@ -94,6 +114,7 @@ final apiClientProvider = Provider<ApiClient>((ref) {
|
||||
return ApiClient(
|
||||
baseUrl: kApiBaseUrl,
|
||||
getAccessToken: () async => ref.read(authProvider).accessToken,
|
||||
onUnauthorized: () async => authNotifier.logout(),
|
||||
onRefreshToken: () => authNotifier.refreshAccessToken(),
|
||||
onSessionExpired: () => authNotifier.sessionExpired(),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
/// Chemins des endpoints REST de l'API Laverie v1.
|
||||
abstract final class ApiEndpoints {
|
||||
// Santé / monitoring
|
||||
static const health = '/health';
|
||||
static const healthDb = '/health/db';
|
||||
|
||||
// Authentification utilisateur
|
||||
static const authRegister = '/auth/register';
|
||||
static const authLogin = '/auth/login';
|
||||
@@ -17,6 +21,7 @@ abstract final class ApiEndpoints {
|
||||
static const establishments = '/establishments';
|
||||
static String establishment(String uuid) => '/establishments/$uuid';
|
||||
static String machine(String uuid) => '/machines/$uuid';
|
||||
static const machineLookup = '/machines/lookup';
|
||||
static String machineAvailability(String uuid) => '/machines/$uuid/availability';
|
||||
static String machinePricing(String uuid) => '/machines/$uuid/pricing';
|
||||
|
||||
@@ -24,6 +29,7 @@ abstract final class ApiEndpoints {
|
||||
static const bookings = '/bookings';
|
||||
static String booking(String uuid) => '/bookings/$uuid';
|
||||
static String bookingCancel(String uuid) => '/bookings/$uuid/cancel';
|
||||
static String bookingMove(String uuid) => '/bookings/$uuid/move';
|
||||
|
||||
// Lavages
|
||||
static const washes = '/washes';
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
/// Helpers pour parser les réponses JSON de l'API Laverie (`success` + `data`).
|
||||
abstract final class ApiResponse { static Map<String, dynamic> payload(dynamic data) {
|
||||
if (data is Map<String, dynamic>) {
|
||||
if (data['data'] is Map<String, dynamic>) {
|
||||
return data['data'] as Map<String, dynamic>;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
throw StateError('Réponse API inattendue');
|
||||
}
|
||||
|
||||
static List<dynamic> list(dynamic data, String key) {
|
||||
final value = payload(data)[key];
|
||||
if (value is List<dynamic>) {
|
||||
return value;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
static Map<String, dynamic> object(dynamic data, String key) {
|
||||
final value = payload(data)[key];
|
||||
if (value is Map<String, dynamic>) {
|
||||
return value;
|
||||
}
|
||||
throw StateError('Champ API "$key" introuvable ou invalide');
|
||||
}
|
||||
|
||||
static String errorMessage(DioException error, {String fallback = 'Erreur réseau'}) {
|
||||
final response = error.response;
|
||||
if (response?.data is Map<String, dynamic>) {
|
||||
final data = response!.data as Map<String, dynamic>;
|
||||
final message = data['message'];
|
||||
if (message is String && message.isNotEmpty) {
|
||||
return _sanitize(message);
|
||||
}
|
||||
}
|
||||
|
||||
return switch (error.type) {
|
||||
DioExceptionType.connectionTimeout ||
|
||||
DioExceptionType.sendTimeout ||
|
||||
DioExceptionType.receiveTimeout =>
|
||||
'Délai d\'attente dépassé',
|
||||
DioExceptionType.connectionError =>
|
||||
'Connexion impossible',
|
||||
_ => fallback,
|
||||
};
|
||||
}
|
||||
|
||||
/// Masque les détails SQL techniques pour l'utilisateur.
|
||||
static String _sanitize(String message) {
|
||||
if (message.contains('SQLSTATE') || message.contains('SQL:') || message.contains('must be of type')) {
|
||||
return 'Erreur serveur — réessayez dans un instant';
|
||||
}
|
||||
return message;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../api/api_client.dart';
|
||||
import '../config/app_config.dart';
|
||||
import '../config/secure_storage_config.dart';
|
||||
import '../../features/auth/domain/auth_user.dart';
|
||||
import 'auth_repository.dart';
|
||||
|
||||
@@ -44,12 +45,33 @@ class AuthState {
|
||||
|
||||
/// Gestionnaire d'état Riverpod pour l'authentification.
|
||||
class AuthNotifier extends StateNotifier<AuthState> {
|
||||
AuthNotifier(this._repository) : super(const AuthState()) {
|
||||
AuthNotifier(this._repository) : super(const AuthState(isLoading: true)) {
|
||||
_restoreSession();
|
||||
}
|
||||
|
||||
final AuthRepository _repository;
|
||||
|
||||
/// Tente de renouveler le token d'accès (appelé par le client API sur 401).
|
||||
Future<String?> refreshAccessToken() async {
|
||||
final refreshed = await _repository.refresh();
|
||||
if (refreshed == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
state = state.copyWith(
|
||||
accessToken: refreshed.accessToken,
|
||||
refreshToken: refreshed.refreshToken,
|
||||
user: refreshed.user ?? state.user,
|
||||
);
|
||||
|
||||
return refreshed.accessToken;
|
||||
}
|
||||
|
||||
/// Session expirée après échec du refresh.
|
||||
Future<void> sessionExpired() async {
|
||||
await logout();
|
||||
}
|
||||
|
||||
Future<void> _restoreSession() async {
|
||||
state = state.copyWith(isLoading: true, clearError: true);
|
||||
|
||||
@@ -149,8 +171,16 @@ class AuthNotifier extends StateNotifier<AuthState> {
|
||||
}
|
||||
|
||||
final authRepositoryProvider = Provider<AuthRepository>((ref) {
|
||||
// Client dédié à l'auth pour éviter une dépendance circulaire avec apiClientProvider.
|
||||
return AuthRepository(apiClient: ApiClient(baseUrl: kApiBaseUrl));
|
||||
final storage = laverieSecureStorage;
|
||||
|
||||
// Token lu depuis le stockage sécurisé (évite la dépendance circulaire avec authProvider).
|
||||
return AuthRepository(
|
||||
apiClient: ApiClient(
|
||||
baseUrl: kApiBaseUrl,
|
||||
getAccessToken: () => storage.read(key: AuthStorageKeys.accessToken),
|
||||
),
|
||||
secureStorage: storage,
|
||||
);
|
||||
});
|
||||
|
||||
final authProvider = StateNotifierProvider<AuthNotifier, AuthState>((ref) {
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
|
||||
import '../api/api_client.dart';
|
||||
import '../api/api_endpoints.dart';
|
||||
import '../api/api_response.dart';
|
||||
import '../config/app_config.dart';
|
||||
import '../config/secure_storage_config.dart';
|
||||
import '../../features/auth/domain/auth_user.dart';
|
||||
@@ -29,7 +30,7 @@ class AuthRepository {
|
||||
},
|
||||
);
|
||||
|
||||
final tokens = AuthTokens.fromJson(response.data as Map<String, dynamic>);
|
||||
final tokens = AuthTokens.fromJson(ApiResponse.payload(response.data));
|
||||
await _persistTokens(tokens);
|
||||
return tokens;
|
||||
}
|
||||
@@ -52,7 +53,7 @@ class AuthRepository {
|
||||
},
|
||||
);
|
||||
|
||||
final tokens = AuthTokens.fromJson(response.data as Map<String, dynamic>);
|
||||
final tokens = AuthTokens.fromJson(ApiResponse.payload(response.data));
|
||||
await _persistTokens(tokens);
|
||||
return tokens;
|
||||
}
|
||||
@@ -68,23 +69,21 @@ class AuthRepository {
|
||||
data: {'refresh_token': refreshToken},
|
||||
);
|
||||
|
||||
final tokens = AuthTokens.fromJson(response.data as Map<String, dynamic>);
|
||||
final tokens = AuthTokens.fromJson(ApiResponse.payload(response.data));
|
||||
await _persistTokens(tokens);
|
||||
return tokens;
|
||||
}
|
||||
|
||||
Future<AuthUser?> fetchCurrentUser() async {
|
||||
final response = await _apiClient.get(ApiEndpoints.authMe);
|
||||
final data = response.data;
|
||||
final payload = ApiResponse.payload(response.data);
|
||||
final userJson = payload['user'] as Map<String, dynamic>?;
|
||||
|
||||
if (data is Map<String, dynamic>) {
|
||||
if (data.containsKey('data')) {
|
||||
return AuthUser.fromJson(data['data'] as Map<String, dynamic>);
|
||||
}
|
||||
return AuthUser.fromJson(data);
|
||||
if (userJson != null) {
|
||||
return AuthUser.fromJson(userJson);
|
||||
}
|
||||
|
||||
return null;
|
||||
return AuthUser.fromJson(payload);
|
||||
}
|
||||
|
||||
Future<void> logout() async {
|
||||
|
||||
@@ -5,23 +5,34 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../auth/auth_provider.dart';
|
||||
import '../../features/auth/presentation/login_screen.dart';
|
||||
import '../../features/auth/presentation/register_screen.dart';
|
||||
import '../../features/auth/presentation/splash_screen.dart';
|
||||
import '../../features/home/presentation/home_screen.dart';
|
||||
import '../../features/establishments/presentation/establishment_detail_screen.dart';
|
||||
import '../../features/wallet/presentation/wallet_screen.dart';
|
||||
import '../../features/booking/presentation/booking_modify_screen.dart';
|
||||
import '../../features/booking/presentation/bookings_screen.dart';
|
||||
import '../../features/machines/presentation/machine_action_screen.dart';
|
||||
import '../../features/machines/presentation/machine_booking_screen.dart';
|
||||
import '../../features/wash/presentation/qr_scanner_screen.dart';
|
||||
import '../../features/wash/presentation/wash_screen.dart';
|
||||
import '../../features/profile/presentation/profile_screen.dart';
|
||||
import '../widgets/main_shell.dart';
|
||||
|
||||
/// Routes nommées de l'application.
|
||||
abstract final class AppRoutes {
|
||||
static const splash = '/splash';
|
||||
static const login = '/login';
|
||||
static const register = '/register';
|
||||
static const home = '/';
|
||||
static const wallet = '/wallet';
|
||||
static const bookings = '/bookings';
|
||||
static const washes = '/washes';
|
||||
static const washScan = '/washes/scan';
|
||||
static const profile = '/profile';
|
||||
static const establishment = '/establishments/:uuid';
|
||||
static String machineAction(String uuid) => '/machines/$uuid/action';
|
||||
static String machineBooking(String uuid) => '/machines/$uuid/book';
|
||||
static String bookingModify(String uuid) => '/bookings/$uuid/edit';
|
||||
}
|
||||
|
||||
/// Configuration GoRouter avec redirection selon l'état d'authentification.
|
||||
@@ -29,12 +40,24 @@ final appRouterProvider = Provider<GoRouter>((ref) {
|
||||
final authState = ref.watch(authProvider);
|
||||
|
||||
return GoRouter(
|
||||
initialLocation: AppRoutes.home,
|
||||
initialLocation: AppRoutes.splash,
|
||||
refreshListenable: GoRouterRefreshStream(ref),
|
||||
redirect: (context, state) {
|
||||
final location = state.matchedLocation;
|
||||
final onSplash = location == AppRoutes.splash;
|
||||
final isAuthRoute = location == AppRoutes.login || location == AppRoutes.register;
|
||||
|
||||
// Restauration de session en cours → écran de chargement.
|
||||
if (authState.isLoading) {
|
||||
return onSplash ? null : AppRoutes.splash;
|
||||
}
|
||||
|
||||
// Session restaurée → quitter le splash.
|
||||
if (onSplash) {
|
||||
return authState.isAuthenticated ? AppRoutes.home : AppRoutes.login;
|
||||
}
|
||||
|
||||
final isAuthenticated = authState.isAuthenticated;
|
||||
final isAuthRoute = state.matchedLocation == AppRoutes.login ||
|
||||
state.matchedLocation == AppRoutes.register;
|
||||
|
||||
if (!isAuthenticated && !isAuthRoute) {
|
||||
return AppRoutes.login;
|
||||
@@ -47,6 +70,10 @@ final appRouterProvider = Provider<GoRouter>((ref) {
|
||||
return null;
|
||||
},
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: AppRoutes.splash,
|
||||
builder: (context, state) => const SplashScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
path: AppRoutes.login,
|
||||
builder: (context, state) => const LoginScreen(),
|
||||
@@ -55,9 +82,30 @@ final appRouterProvider = Provider<GoRouter>((ref) {
|
||||
path: AppRoutes.register,
|
||||
builder: (context, state) => const RegisterScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
path: AppRoutes.home,
|
||||
builder: (context, state) => const HomeScreen(),
|
||||
ShellRoute(
|
||||
builder: (context, state, child) => MainShell(child: child),
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: AppRoutes.home,
|
||||
builder: (context, state) => const HomeScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
path: AppRoutes.bookings,
|
||||
builder: (context, state) => const BookingsScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
path: AppRoutes.washes,
|
||||
builder: (context, state) => const WashScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
path: AppRoutes.wallet,
|
||||
builder: (context, state) => const WalletScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
path: AppRoutes.profile,
|
||||
builder: (context, state) => const ProfileScreen(),
|
||||
),
|
||||
],
|
||||
),
|
||||
GoRoute(
|
||||
path: AppRoutes.establishment,
|
||||
@@ -67,20 +115,29 @@ final appRouterProvider = Provider<GoRouter>((ref) {
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: AppRoutes.wallet,
|
||||
builder: (context, state) => const WalletScreen(),
|
||||
path: AppRoutes.washScan,
|
||||
builder: (context, state) => const QrScannerScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
path: AppRoutes.bookings,
|
||||
builder: (context, state) => const BookingsScreen(),
|
||||
path: '/machines/:uuid/action',
|
||||
builder: (context, state) {
|
||||
final uuid = state.pathParameters['uuid']!;
|
||||
return MachineActionScreen(machineUuid: uuid);
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: AppRoutes.washes,
|
||||
builder: (context, state) => const WashScreen(),
|
||||
path: '/machines/:uuid/book',
|
||||
builder: (context, state) {
|
||||
final uuid = state.pathParameters['uuid']!;
|
||||
return MachineBookingScreen(machineUuid: uuid);
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: AppRoutes.profile,
|
||||
builder: (context, state) => const ProfileScreen(),
|
||||
path: '/bookings/:uuid/edit',
|
||||
builder: (context, state) {
|
||||
final uuid = state.pathParameters['uuid']!;
|
||||
return BookingModifyScreen(bookingUuid: uuid);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Palette équilibrée — moderne sans excès « web app ».
|
||||
abstract final class AppColors {
|
||||
static const primary = Color(0xFF2563EB);
|
||||
static const primaryDark = Color(0xFF1D4ED8);
|
||||
static const secondary = Color(0xFF0D9488);
|
||||
|
||||
static const background = Color(0xFFF1F5F9);
|
||||
static const surface = Color(0xFFFFFFFF);
|
||||
static const surfaceVariant = Color(0xFFE2E8F0);
|
||||
static const divider = Color(0xFFE2E8F0);
|
||||
|
||||
static const textPrimary = Color(0xFF0F172A);
|
||||
static const textSecondary = Color(0xFF64748B);
|
||||
|
||||
static const success = Color(0xFF059669);
|
||||
static const warning = Color(0xFFD97706);
|
||||
static const error = Color(0xFFDC2626);
|
||||
|
||||
/// Statuts machines — code couleur type WashOnline.
|
||||
static const machineAvailable = Color(0xFF16A34A);
|
||||
static const machineRunning = Color(0xFF2563EB);
|
||||
static const machineReserved = Color(0xFFEA580C);
|
||||
static const machineOffline = Color(0xFF94A3B8);
|
||||
|
||||
static const gradientPrimary = LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [Color(0xFF2563EB), Color(0xFF1D4ED8)],
|
||||
);
|
||||
|
||||
static const gradientAccent = LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [Color(0xFF2563EB), Color(0xFF0D9488)],
|
||||
);
|
||||
|
||||
static const gradientSoft = LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [Color(0xFFEFF6FF), Color(0xFFF1F5F9)],
|
||||
);
|
||||
|
||||
/// Deux accents alternés pour les cartes (pas d'arc-en-ciel).
|
||||
static Color cardAccent(int index) => index.isEven ? primary : secondary;
|
||||
}
|
||||
@@ -1,45 +1,121 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'app_colors.dart';
|
||||
|
||||
/// Thème visuel de l'application Laverie.
|
||||
class AppTheme {
|
||||
AppTheme._();
|
||||
|
||||
static const Color _primary = Color(0xFF1565C0);
|
||||
static const Color _secondary = Color(0xFF26A69A);
|
||||
|
||||
static ThemeData get light {
|
||||
final colorScheme = ColorScheme.fromSeed(
|
||||
seedColor: _primary,
|
||||
secondary: _secondary,
|
||||
brightness: Brightness.light,
|
||||
const colorScheme = ColorScheme.light(
|
||||
primary: AppColors.primary,
|
||||
onPrimary: Colors.white,
|
||||
primaryContainer: Color(0xFFDBEAFE),
|
||||
onPrimaryContainer: AppColors.primaryDark,
|
||||
secondary: AppColors.secondary,
|
||||
onSecondary: Colors.white,
|
||||
error: AppColors.error,
|
||||
onError: Colors.white,
|
||||
surface: AppColors.surface,
|
||||
onSurface: AppColors.textPrimary,
|
||||
onSurfaceVariant: AppColors.textSecondary,
|
||||
);
|
||||
|
||||
return ThemeData(
|
||||
useMaterial3: true,
|
||||
colorScheme: colorScheme,
|
||||
appBarTheme: AppBarTheme(
|
||||
centerTitle: true,
|
||||
backgroundColor: colorScheme.primary,
|
||||
foregroundColor: colorScheme.onPrimary,
|
||||
scaffoldBackgroundColor: AppColors.background,
|
||||
appBarTheme: const AppBarTheme(
|
||||
centerTitle: false,
|
||||
elevation: 0,
|
||||
scrolledUnderElevation: 0,
|
||||
backgroundColor: AppColors.surface,
|
||||
foregroundColor: AppColors.textPrimary,
|
||||
surfaceTintColor: Colors.transparent,
|
||||
systemOverlayStyle: SystemUiOverlayStyle.dark,
|
||||
titleTextStyle: TextStyle(
|
||||
color: AppColors.textPrimary,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
cardTheme: CardThemeData(
|
||||
elevation: 1,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
shadowColor: Colors.black.withValues(alpha: 0.06),
|
||||
color: AppColors.surface,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)),
|
||||
margin: EdgeInsets.zero,
|
||||
),
|
||||
dividerTheme: const DividerThemeData(color: AppColors.divider, thickness: 1),
|
||||
inputDecorationTheme: InputDecorationTheme(
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12)),
|
||||
filled: true,
|
||||
fillColor: AppColors.surface,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: const BorderSide(color: AppColors.divider),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: const BorderSide(color: AppColors.primary, width: 1.5),
|
||||
),
|
||||
prefixIconColor: AppColors.textSecondary,
|
||||
),
|
||||
elevatedButtonTheme: ElevatedButtonThemeData(
|
||||
style: ElevatedButton.styleFrom(
|
||||
minimumSize: const Size.fromHeight(48),
|
||||
elevation: 0,
|
||||
backgroundColor: AppColors.primary,
|
||||
foregroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
textStyle: const TextStyle(fontWeight: FontWeight.w600, fontSize: 16),
|
||||
),
|
||||
),
|
||||
outlinedButtonTheme: OutlinedButtonThemeData(
|
||||
style: OutlinedButton.styleFrom(
|
||||
minimumSize: const Size.fromHeight(48),
|
||||
foregroundColor: AppColors.primary,
|
||||
side: const BorderSide(color: AppColors.divider),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
),
|
||||
),
|
||||
floatingActionButtonTheme: FloatingActionButtonThemeData(
|
||||
backgroundColor: colorScheme.secondary,
|
||||
foregroundColor: colorScheme.onSecondary,
|
||||
floatingActionButtonTheme: const FloatingActionButtonThemeData(
|
||||
elevation: 3,
|
||||
backgroundColor: AppColors.primary,
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
navigationBarTheme: NavigationBarThemeData(
|
||||
elevation: 0,
|
||||
height: 64,
|
||||
backgroundColor: AppColors.surface,
|
||||
indicatorColor: AppColors.primary.withValues(alpha: 0.12),
|
||||
surfaceTintColor: Colors.transparent,
|
||||
labelTextStyle: WidgetStateProperty.resolveWith((states) {
|
||||
if (states.contains(WidgetState.selected)) {
|
||||
return const TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: AppColors.primary);
|
||||
}
|
||||
return const TextStyle(fontSize: 12, color: AppColors.textSecondary);
|
||||
}),
|
||||
iconTheme: WidgetStateProperty.resolveWith((states) {
|
||||
if (states.contains(WidgetState.selected)) {
|
||||
return const IconThemeData(color: AppColors.primary, size: 24);
|
||||
}
|
||||
return const IconThemeData(color: AppColors.textSecondary, size: 24);
|
||||
}),
|
||||
),
|
||||
listTileTheme: const ListTileThemeData(
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||||
),
|
||||
textTheme: const TextTheme(
|
||||
headlineMedium: TextStyle(fontSize: 22, fontWeight: FontWeight.w600, color: AppColors.textPrimary),
|
||||
titleMedium: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: AppColors.textPrimary),
|
||||
bodyLarge: TextStyle(fontSize: 16, color: AppColors.textPrimary),
|
||||
bodyMedium: TextStyle(fontSize: 14, color: AppColors.textSecondary),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'app_colors.dart';
|
||||
|
||||
/// Couleurs et libellés des statuts machine (inspiré WashOnline, plus lisible).
|
||||
abstract final class MachineStatusTheme {
|
||||
static Color color(String status) => switch (status) {
|
||||
'available' => AppColors.machineAvailable,
|
||||
'running' => AppColors.machineRunning,
|
||||
'reserved' => AppColors.machineReserved,
|
||||
'maintenance' || 'offline' || 'error' => AppColors.machineOffline,
|
||||
_ => AppColors.textSecondary,
|
||||
};
|
||||
|
||||
static String label(String status) => switch (status) {
|
||||
'available' => 'Libre',
|
||||
'running' => 'En cours',
|
||||
'reserved' => 'Réservée',
|
||||
'maintenance' => 'Maintenance',
|
||||
'offline' => 'Hors ligne',
|
||||
'error' => 'Erreur',
|
||||
_ => status,
|
||||
};
|
||||
|
||||
static IconData iconForType(String type) => type.startsWith('dryer')
|
||||
? Icons.air_outlined
|
||||
: Icons.water_drop_outlined;
|
||||
|
||||
static bool canStart(String status) => status == 'available';
|
||||
}
|
||||
@@ -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!)),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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',
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user