You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

207 line
6.3KB

  1. import 'package:flutter/material.dart';
  2. import '../../../core/theme/colors.dart';
  3. import '../../../data/models/user_profile.dart';
  4. // L'import des routes n'est plus nécessaire ici pour la navigation, mais on le garde pour la propreté.
  5. import 'package:social_content_creator/routes/app_routes.dart';
  6. final class ProfileSetupScreen extends StatefulWidget {
  7. const ProfileSetupScreen({super.key});
  8. @override
  9. State<ProfileSetupScreen> createState() => _ProfileSetupScreenState();
  10. }
  11. class _ProfileSetupScreenState extends State<ProfileSetupScreen> {
  12. final List<UserProfile> _profiles = [];
  13. @override
  14. void initState() {
  15. super.initState();
  16. _addProfile();
  17. }
  18. void _addProfile() {
  19. setState(() {
  20. _profiles.add(
  21. const UserProfile(
  22. profession: '',
  23. tone: MessageTone.normal,
  24. textStyle: TextStyleEnum.classic,
  25. ),
  26. );
  27. });
  28. }
  29. void _updateProfile(int index, UserProfile profile) {
  30. setState(() => _profiles[index] = profile);
  31. }
  32. void _removeProfile(int index) {
  33. if (_profiles.length > 1) {
  34. setState(() => _profiles.removeAt(index));
  35. }
  36. }
  37. @override
  38. Widget build(BuildContext context) {
  39. return Scaffold(
  40. appBar: AppBar(title: const Text('Créer votre profil')),
  41. body: SafeArea(
  42. child: Column(
  43. children: [
  44. Expanded(
  45. child: SingleChildScrollView(
  46. padding: const EdgeInsets.all(20),
  47. child: Column(
  48. crossAxisAlignment: CrossAxisAlignment.start,
  49. children: [
  50. Text(
  51. 'Configurez vos profils',
  52. style: Theme.of(context).textTheme.headlineSmall,
  53. ),
  54. const SizedBox(height: 24),
  55. ..._profiles.asMap().entries.map((e) {
  56. final (index, profile) = (e.key, e.value);
  57. return _ProfileCard(
  58. profile: profile,
  59. onUpdate: (p) => _updateProfile(index, p),
  60. onRemove: _profiles.length > 1
  61. ? () => _removeProfile(index)
  62. : null,
  63. index: index,
  64. );
  65. }),
  66. if (_profiles.length < 5) ...[
  67. const SizedBox(height: 16),
  68. OutlinedButton.icon(
  69. onPressed: _addProfile,
  70. icon: const Icon(Icons.add),
  71. label: const Text('Ajouter un profil'),
  72. ),
  73. ],
  74. ],
  75. ),
  76. ),
  77. ),
  78. Container(
  79. padding: const EdgeInsets.all(20),
  80. child: SizedBox(
  81. width: double.infinity,
  82. child: FilledButton(
  83. onPressed: _profiles.any((p) => p.profession.isNotEmpty)
  84. ? () {
  85. // --- CORRECTION ---
  86. // 1. Logique pour sauvegarder les profils (à ajouter si nécessaire)
  87. //
  88. // 2. On ferme simplement l'écran de configuration pour revenir
  89. // à l'écran qui l'a appelé (HomeScreen).
  90. Navigator.pop(context);
  91. }
  92. : null,
  93. child: const Text('Enregistrer et Terminer'),
  94. ),
  95. ),
  96. ),
  97. ],
  98. ),
  99. ),
  100. );
  101. }
  102. }
  103. // ... Le widget _ProfileCard reste inchangé ...
  104. class _ProfileCard extends StatefulWidget {
  105. final UserProfile profile;
  106. final Function(UserProfile) onUpdate;
  107. final VoidCallback? onRemove;
  108. final int index;
  109. const _ProfileCard({
  110. required this.profile,
  111. required this.onUpdate,
  112. this.onRemove,
  113. required this.index,
  114. });
  115. @override
  116. State<_ProfileCard> createState() => _ProfileCardState();
  117. }
  118. class _ProfileCardState extends State<_ProfileCard> {
  119. late final TextEditingController _controller;
  120. @override
  121. void initState() {
  122. super.initState();
  123. _controller = TextEditingController(text: widget.profile.profession);
  124. }
  125. @override
  126. void didUpdateWidget(_ProfileCard oldWidget) {
  127. super.didUpdateWidget(oldWidget);
  128. if (widget.profile.profession != _controller.text) {
  129. _controller.text = widget.profile.profession;
  130. }
  131. }
  132. @override
  133. void dispose() {
  134. _controller.dispose();
  135. super.dispose();
  136. }
  137. @override
  138. Widget build(BuildContext context) {
  139. return Card(
  140. margin: const EdgeInsets.only(bottom: 16),
  141. child: Padding(
  142. padding: const EdgeInsets.all(16),
  143. child: Column(
  144. crossAxisAlignment: CrossAxisAlignment.start,
  145. children: [
  146. Row(
  147. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  148. children: [
  149. Text('Profil ${widget.index + 1}'),
  150. if (widget.onRemove != null)
  151. IconButton(icon: const Icon(Icons.close), onPressed: widget.onRemove),
  152. ],
  153. ),
  154. const SizedBox(height: 16),
  155. TextField(
  156. controller: _controller,
  157. decoration: const InputDecoration(labelText: 'Métier'),
  158. onChanged: (v) => widget.onUpdate(widget.profile.copyWith(profession: v)),
  159. ),
  160. const SizedBox(height: 16),
  161. Text('Ton:', style: Theme.of(context).textTheme.bodySmall),
  162. Wrap(
  163. spacing: 8,
  164. children: MessageTone.values.map((t) {
  165. return FilterChip(
  166. label: Text(t.displayName),
  167. selected: widget.profile.tone == t,
  168. onSelected: (_) => widget.onUpdate(widget.profile.copyWith(tone: t)),
  169. );
  170. }).toList(),
  171. ),
  172. const SizedBox(height: 16),
  173. Text('Style:', style: Theme.of(context).textTheme.bodySmall),
  174. Wrap(
  175. spacing: 8,
  176. children: TextStyleEnum.values.map((s) {
  177. return FilterChip(
  178. label: Text(s.displayName),
  179. selected: widget.profile.textStyle == s,
  180. onSelected: (_) => widget.onUpdate(widget.profile.copyWith(textStyle: s)),
  181. );
  182. }).toList(),
  183. ),
  184. ],
  185. ),
  186. ),
  187. );
  188. }
  189. }