
Refactors the login page and model for improved separation of concerns. Moves navigation logic from the model to the page using success callbacks. Integrates a dedicated primary button component for the login action, showing loading state. Adds a new secure route for a product form page and updates the scanner page to navigate to it when viewing scanned product details. Simplifies the callback signature for viewing product details in the scanned product component. Also includes minor adjustments to the splash screen delay and theme definition.
62 lines
1.8 KiB
Dart
62 lines
1.8 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';
|
|
|
|
// Groupe des routes sécurisées
|
|
@TypedGoRoute<SecureRoute>(
|
|
path: '/$_securePage',
|
|
routes: [
|
|
TypedGoRoute<HomeRoute>(path: _homePage),
|
|
TypedGoRoute<ScannerRoute>(path: _scannerPage),
|
|
TypedGoRoute<ProductFormRoute>(path: _productFormPage),
|
|
],
|
|
)
|
|
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();
|
|
|
|
@override
|
|
Widget build(BuildContext context, GoRouterState state) => ProductFormPage();
|
|
}
|