import 'package:flutter/material.dart'; import '../../../core/theme/colors.dart'; import '../../../data/models/user_profile.dart'; // L'import des routes n'est plus nécessaire ici pour la navigation, mais on le garde pour la propreté. import 'package:social_content_creator/routes/app_routes.dart'; final class ProfileSetupScreen extends StatefulWidget { const ProfileSetupScreen({super.key}); @override State createState() => _ProfileSetupScreenState(); } class _ProfileSetupScreenState extends State { final List _profiles = []; @override void initState() { super.initState(); _addProfile(); } void _addProfile() { setState(() { _profiles.add( const UserProfile( profession: '', tone: MessageTone.normal, textStyle: TextStyleEnum.classic, ), ); }); } void _updateProfile(int index, UserProfile profile) { setState(() => _profiles[index] = profile); } void _removeProfile(int index) { if (_profiles.length > 1) { setState(() => _profiles.removeAt(index)); } } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Créer votre profil')), body: SafeArea( child: Column( children: [ Expanded( child: SingleChildScrollView( padding: const EdgeInsets.all(20), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( 'Configurez vos profils', style: Theme.of(context).textTheme.headlineSmall, ), const SizedBox(height: 24), ..._profiles.asMap().entries.map((e) { final (index, profile) = (e.key, e.value); return _ProfileCard( profile: profile, onUpdate: (p) => _updateProfile(index, p), onRemove: _profiles.length > 1 ? () => _removeProfile(index) : null, index: index, ); }), if (_profiles.length < 5) ...[ const SizedBox(height: 16), OutlinedButton.icon( onPressed: _addProfile, icon: const Icon(Icons.add), label: const Text('Ajouter un profil'), ), ], ], ), ), ), Container( padding: const EdgeInsets.all(20), child: SizedBox( width: double.infinity, child: FilledButton( onPressed: _profiles.any((p) => p.profession.isNotEmpty) ? () { // --- CORRECTION --- // 1. Logique pour sauvegarder les profils (à ajouter si nécessaire) // // 2. On ferme simplement l'écran de configuration pour revenir // à l'écran qui l'a appelé (HomeScreen). Navigator.pop(context); } : null, child: const Text('Enregistrer et Terminer'), ), ), ), ], ), ), ); } } // ... Le widget _ProfileCard reste inchangé ... class _ProfileCard extends StatefulWidget { final UserProfile profile; final Function(UserProfile) onUpdate; final VoidCallback? onRemove; final int index; const _ProfileCard({ required this.profile, required this.onUpdate, this.onRemove, required this.index, }); @override State<_ProfileCard> createState() => _ProfileCardState(); } class _ProfileCardState extends State<_ProfileCard> { late final TextEditingController _controller; @override void initState() { super.initState(); _controller = TextEditingController(text: widget.profile.profession); } @override void didUpdateWidget(_ProfileCard oldWidget) { super.didUpdateWidget(oldWidget); if (widget.profile.profession != _controller.text) { _controller.text = widget.profile.profession; } } @override void dispose() { _controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Card( margin: const EdgeInsets.only(bottom: 16), child: Padding( padding: const EdgeInsets.all(16), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text('Profil ${widget.index + 1}'), if (widget.onRemove != null) IconButton(icon: const Icon(Icons.close), onPressed: widget.onRemove), ], ), const SizedBox(height: 16), TextField( controller: _controller, decoration: const InputDecoration(labelText: 'Métier'), onChanged: (v) => widget.onUpdate(widget.profile.copyWith(profession: v)), ), const SizedBox(height: 16), Text('Ton:', style: Theme.of(context).textTheme.bodySmall), Wrap( spacing: 8, children: MessageTone.values.map((t) { return FilterChip( label: Text(t.displayName), selected: widget.profile.tone == t, onSelected: (_) => widget.onUpdate(widget.profile.copyWith(tone: t)), ); }).toList(), ), const SizedBox(height: 16), Text('Style:', style: Theme.of(context).textTheme.bodySmall), Wrap( spacing: 8, children: TextStyleEnum.values.map((s) { return FilterChip( label: Text(s.displayName), selected: widget.profile.textStyle == s, onSelected: (_) => widget.onUpdate(widget.profile.copyWith(textStyle: s)), ); }).toList(), ), ], ), ), ); } }