Refactorisation complète du parcours d'inscription des parents pour utiliser Provider au lieu du passage de données par paramètres de navigation. Modifications principales : - Utilisation de Provider pour partager UserRegistrationData entre les étapes - Simplification du routeur (suppression des paramètres) - Amélioration de la persistance des données entre les étapes - Meilleure expérience utilisateur lors de la navigation Fichiers modifiés : - models/user_registration_data.dart : Modèle avec ChangeNotifier - screens/auth/parent_register_step1-5_screen.dart : Intégration Provider - navigation/app_router.dart : Simplification du routing - main.dart : Configuration du Provider - login_screen.dart : Ajout navigation vers inscription - register_choice_screen.dart : Navigation vers parcours parent/AM - utils/data_generator.dart : Génération de données de test Refs: #38 (Étape 3 Enfants), #39 (Étapes 4-6 Finalisation)
101 lines
3.6 KiB
Dart
101 lines
3.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import '../screens/auth/login_screen.dart';
|
|
import '../screens/auth/register_choice_screen.dart';
|
|
import '../screens/auth/parent_register_step1_screen.dart';
|
|
import '../screens/auth/parent_register_step2_screen.dart';
|
|
import '../screens/auth/parent_register_step3_screen.dart';
|
|
import '../screens/auth/parent_register_step4_screen.dart';
|
|
import '../screens/auth/parent_register_step5_screen.dart';
|
|
import '../screens/home/home_screen.dart';
|
|
import '../models/user_registration_data.dart';
|
|
|
|
class AppRouter {
|
|
static const String login = '/login';
|
|
static const String registerChoice = '/register-choice';
|
|
static const String parentRegisterStep1 = '/parent-register/step1';
|
|
static const String parentRegisterStep2 = '/parent-register/step2';
|
|
static const String parentRegisterStep3 = '/parent-register/step3';
|
|
static const String parentRegisterStep4 = '/parent-register/step4';
|
|
static const String parentRegisterStep5 = '/parent-register/step5';
|
|
static const String home = '/home';
|
|
|
|
static Route<dynamic> generateRoute(RouteSettings settings) {
|
|
Widget screen;
|
|
bool slideTransition = false;
|
|
Object? args = settings.arguments;
|
|
|
|
Widget buildErrorScreen(String step) {
|
|
print("Erreur: Données UserRegistrationData manquantes ou de mauvais type pour l'étape $step");
|
|
return const ParentRegisterStep1Screen();
|
|
}
|
|
|
|
switch (settings.name) {
|
|
case login:
|
|
screen = const LoginPage();
|
|
break;
|
|
case registerChoice:
|
|
screen = const RegisterChoiceScreen();
|
|
slideTransition = true;
|
|
break;
|
|
case parentRegisterStep1:
|
|
screen = const ParentRegisterStep1Screen();
|
|
slideTransition = true;
|
|
break;
|
|
case parentRegisterStep2:
|
|
if (args is UserRegistrationData) {
|
|
screen = ParentRegisterStep2Screen(registrationData: args);
|
|
} else {
|
|
screen = buildErrorScreen('2');
|
|
}
|
|
slideTransition = true;
|
|
break;
|
|
case parentRegisterStep3:
|
|
if (args is UserRegistrationData) {
|
|
screen = ParentRegisterStep3Screen(registrationData: args);
|
|
} else {
|
|
screen = buildErrorScreen('3');
|
|
}
|
|
slideTransition = true;
|
|
break;
|
|
case parentRegisterStep4:
|
|
if (args is UserRegistrationData) {
|
|
screen = ParentRegisterStep4Screen(registrationData: args);
|
|
} else {
|
|
screen = buildErrorScreen('4');
|
|
}
|
|
slideTransition = true;
|
|
break;
|
|
case parentRegisterStep5:
|
|
screen = const ParentRegisterStep5Screen();
|
|
slideTransition = true;
|
|
break;
|
|
case home:
|
|
screen = const HomeScreen();
|
|
break;
|
|
default:
|
|
screen = Scaffold(
|
|
body: Center(
|
|
child: Text('Route non définie : ${settings.name}'),
|
|
),
|
|
);
|
|
}
|
|
|
|
if (slideTransition) {
|
|
return PageRouteBuilder(
|
|
pageBuilder: (context, animation, secondaryAnimation) => screen,
|
|
transitionsBuilder: (context, animation, secondaryAnimation, child) {
|
|
const begin = Offset(1.0, 0.0);
|
|
const end = Offset.zero;
|
|
const curve = Curves.easeInOut;
|
|
var tween = Tween(begin: begin, end: end).chain(CurveTween(curve: curve));
|
|
var offsetAnimation = animation.drive(tween);
|
|
return SlideTransition(position: offsetAnimation, child: child);
|
|
},
|
|
transitionDuration: const Duration(milliseconds: 400),
|
|
);
|
|
} else {
|
|
return MaterialPageRoute(builder: (_) => screen);
|
|
}
|
|
}
|
|
} |