
Adds an `image` field to the user data structure to support profile pictures. Introduces a new profile page and sets up navigation from the home screen. Changes the product list page provider to auto dispose for improved resource management.
82 lines
2.4 KiB
Dart
82 lines
2.4 KiB
Dart
import 'package:barcode_scanner/pages/login_page/login_page_model.dart';
|
|
import 'package:barcode_scanner/provider_container.dart';
|
|
import 'package:barcode_scanner/router/go_router_builder.dart';
|
|
import 'package:barcode_scanner/pages/pages.dart';
|
|
import 'package:flutter/material.dart';
|
|
export 'package:go_router/go_router.dart';
|
|
part 'go_secure_router_builder.g.dart';
|
|
|
|
final appSecureRoutes = $appRoutes;
|
|
|
|
const String _securePage = 'SecurePage';
|
|
const String _homePage = 'HomePage';
|
|
const String _scannerPage = 'ScannerPage';
|
|
const String _productFormPage = 'ProductFormPage';
|
|
const String _productListPage = 'ProductListPage';
|
|
const String _profilePage = "ProfilePage";
|
|
|
|
// Groupe des routes sécurisées
|
|
@TypedGoRoute<SecureRoute>(
|
|
path: '/$_securePage',
|
|
routes: [
|
|
TypedGoRoute<HomeRoute>(path: _homePage),
|
|
TypedGoRoute<ScannerRoute>(path: _scannerPage),
|
|
TypedGoRoute<ProductFormRoute>(path: _productFormPage),
|
|
TypedGoRoute<ProductListRoute>(path: _productListPage),
|
|
TypedGoRoute<ProfileRoute>(path: _profilePage),
|
|
],
|
|
)
|
|
class SecureRoute extends GoRouteData with _$SecureRoute {
|
|
const SecureRoute();
|
|
@override
|
|
Widget build(BuildContext context, GoRouterState state) => SizedBox();
|
|
|
|
/// Logique de redirection pour sécuriser les sous-routes
|
|
@override
|
|
String? redirect(BuildContext context, GoRouterState state) {
|
|
final authState = providerContainer
|
|
.read(loginPageModelProvider)
|
|
.status
|
|
.isLogged;
|
|
if (!authState) return SplashRoute().location;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
class HomeRoute extends GoRouteData with _$HomeRoute {
|
|
const HomeRoute();
|
|
|
|
@override
|
|
Widget build(BuildContext context, GoRouterState state) => HomePage();
|
|
}
|
|
|
|
class ScannerRoute extends GoRouteData with _$ScannerRoute {
|
|
const ScannerRoute();
|
|
|
|
@override
|
|
Widget build(BuildContext context, GoRouterState state) => ScannerPage();
|
|
}
|
|
|
|
class ProductFormRoute extends GoRouteData with _$ProductFormRoute {
|
|
const ProductFormRoute({required this.id});
|
|
final int id;
|
|
|
|
@override
|
|
Widget build(BuildContext context, GoRouterState state) =>
|
|
ProductFormPage(id: id);
|
|
}
|
|
|
|
class ProductListRoute extends GoRouteData with _$ProductListRoute {
|
|
const ProductListRoute();
|
|
|
|
@override
|
|
Widget build(BuildContext context, GoRouterState state) => ProductListPage();
|
|
}
|
|
|
|
class ProfileRoute extends GoRouteData with _$ProfileRoute {
|
|
const ProfileRoute();
|
|
|
|
@override
|
|
Widget build(BuildContext context, GoRouterState state) => ProfilePage();
|
|
}
|