選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

78 行
1.9KB

  1. import 'package:flutter/foundation.dart';
  2. /// Enum pour les tons de message (Dart 3.10 with enhanced members)
  3. enum MessageTone {
  4. fun('Fun', '😄'),
  5. serious('Sérieux', '💼'),
  6. normal('Normal', '✨'),
  7. oleOle('Olé Olé', '🔥');
  8. final String displayName;
  9. final String emoji;
  10. const MessageTone(this.displayName, this.emoji);
  11. }
  12. /// Enum pour le style de texte
  13. enum TextStyleEnum {
  14. classic('Classique'),
  15. modern('Moderne'),
  16. playful('Ludique');
  17. final String displayName;
  18. const TextStyleEnum(this.displayName);
  19. }
  20. /// Modèle de profil utilisateur (Dart 3.10)
  21. final class UserProfile {
  22. final String profession;
  23. final MessageTone tone;
  24. final TextStyleEnum textStyle;
  25. const UserProfile({
  26. required this.profession,
  27. required this.tone,
  28. required this.textStyle,
  29. });
  30. /// Records pour extraction facile des données
  31. (String, MessageTone, TextStyleEnum) toRecord() =>
  32. (profession, tone, textStyle);
  33. Map<String, dynamic> toJson() => <String, dynamic>{
  34. 'profession': profession,
  35. 'tone': tone.name,
  36. 'textStyle': textStyle.name,
  37. };
  38. factory UserProfile.fromJson(Map<String, dynamic> json) {
  39. return UserProfile(
  40. profession: json['profession'] as String? ?? '',
  41. tone: MessageTone.values.firstWhere(
  42. (e) => e.name == json['tone'],
  43. orElse: () => MessageTone.normal,
  44. ),
  45. textStyle: TextStyleEnum.values.firstWhere(
  46. (e) => e.name == json['textStyle'],
  47. orElse: () => TextStyleEnum.classic,
  48. ),
  49. );
  50. }
  51. UserProfile copyWith({
  52. String? profession,
  53. MessageTone? tone,
  54. TextStyleEnum? textStyle,
  55. }) {
  56. return UserProfile(
  57. profession: profession ?? this.profession,
  58. tone: tone ?? this.tone,
  59. textStyle: textStyle ?? this.textStyle,
  60. );
  61. }
  62. @override
  63. String toString() =>
  64. 'UserProfile(profession: $profession, tone: ${tone.displayName}, style: ${textStyle.displayName})';
  65. }