Refactorisation des écrans d'inscription pour utiliser les nouveaux widgets : Parent Step 1 (227 → 65 lignes, -71%) - Utilise personal_info_form_screen - Conserve préremplissage des données de test - Couleur : peach Parent Step 2 (273 → 90 lignes, -67%) - Utilise personal_info_form_screen - Toggle "Il y a un 2ème parent" - Checkbox "Même adresse que parent 1" - Couleur : blue Parent Step 4 (247 → 42 lignes, -83%) - Utilise presentation_form_screen - Formulaire de motivation - Couleur : green AM Step 1 (209 → 65 lignes, -69%) - Utilise personal_info_form_screen - Conserve préremplissage des données de test - Couleur : blue AM Step 3 (195 → 45 lignes, -77%) - Utilise presentation_form_screen - Formulaire de présentation - Couleur : peach Total : -709 lignes de code maintenable !
91 lines
3.0 KiB
Dart
91 lines
3.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
import '../../models/user_registration_data.dart';
|
|
import '../../utils/data_generator.dart';
|
|
import '../../widgets/personal_info_form_screen.dart';
|
|
import '../../models/card_assets.dart';
|
|
|
|
class ParentRegisterStep2Screen extends StatelessWidget {
|
|
const ParentRegisterStep2Screen({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final registrationData = Provider.of<UserRegistrationData>(context, listen: false);
|
|
final parent1 = registrationData.parent1;
|
|
final parent2 = registrationData.parent2;
|
|
|
|
bool hasParent2 = parent2 != null;
|
|
bool sameAddress = false;
|
|
|
|
// Générer des données de test si vide
|
|
PersonalInfoData initialData;
|
|
if (parent2 == null || parent2.firstName.isEmpty) {
|
|
final genFirstName = DataGenerator.firstName();
|
|
final genLastName = DataGenerator.lastName();
|
|
sameAddress = DataGenerator.boolean();
|
|
|
|
initialData = PersonalInfoData(
|
|
firstName: genFirstName,
|
|
lastName: genLastName,
|
|
phone: DataGenerator.phone(),
|
|
email: DataGenerator.email(genFirstName, genLastName),
|
|
address: sameAddress ? parent1.address : DataGenerator.address(),
|
|
postalCode: sameAddress ? parent1.postalCode : DataGenerator.postalCode(),
|
|
city: sameAddress ? parent1.city : DataGenerator.city(),
|
|
);
|
|
} else {
|
|
sameAddress = (parent2.address == parent1.address &&
|
|
parent2.postalCode == parent1.postalCode &&
|
|
parent2.city == parent1.city);
|
|
initialData = PersonalInfoData(
|
|
firstName: parent2.firstName,
|
|
lastName: parent2.lastName,
|
|
phone: parent2.phone,
|
|
email: parent2.email,
|
|
address: parent2.address,
|
|
postalCode: parent2.postalCode,
|
|
city: parent2.city,
|
|
);
|
|
}
|
|
|
|
// Adresse de référence pour "même adresse"
|
|
final referenceAddress = PersonalInfoData(
|
|
address: parent1.address,
|
|
postalCode: parent1.postalCode,
|
|
city: parent1.city,
|
|
);
|
|
|
|
return PersonalInfoFormScreen(
|
|
stepText: 'Étape 2/5',
|
|
title: 'Deuxième Parent',
|
|
cardColor: CardColorHorizontal.blue,
|
|
initialData: initialData,
|
|
previousRoute: '/parent-register-step1',
|
|
showSecondPersonToggle: true,
|
|
initialHasSecondPerson: hasParent2,
|
|
showSameAddressCheckbox: true,
|
|
initialSameAddress: sameAddress,
|
|
referenceAddressData: referenceAddress,
|
|
onSubmit: (data, {hasSecondPerson, sameAddress}) {
|
|
if (hasSecondPerson == true) {
|
|
registrationData.updateParent2(
|
|
firstName: data.firstName,
|
|
lastName: data.lastName,
|
|
phone: data.phone,
|
|
email: data.email,
|
|
address: data.address,
|
|
postalCode: data.postalCode,
|
|
city: data.city,
|
|
password: '',
|
|
);
|
|
} else {
|
|
registrationData.removeParent2();
|
|
}
|
|
context.go('/parent-register-step3');
|
|
},
|
|
);
|
|
}
|
|
}
|