Skip to content

Commit 97fee74

Browse files
committed
add errror message and update additional text
1 parent 81b2fe1 commit 97fee74

17 files changed

+268
-109
lines changed

app/lib/l10n/gen/ouds_flutter_app_localizations.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,12 @@ abstract class AppLocalizations {
389389
/// **'Error'**
390390
String get app_components_common_error_label;
391391

392+
/// No description provided for @app_components_common_error_message.
393+
///
394+
/// In en, this message translates to:
395+
/// **'Error message'**
396+
String get app_components_common_error_message;
397+
392398
/// No description provided for @app_components_common_layout_label.
393399
///
394400
/// In en, this message translates to:
@@ -653,11 +659,11 @@ abstract class AppLocalizations {
653659
/// **'Outlined'**
654660
String get app_components_radioButton_radioButtonItem_outlined_label;
655661

656-
/// No description provided for @app_components_radioButton_radioButtonItem_additionalLabel_label.
662+
/// No description provided for @app_components_radioButton_radioButtonItem_extraLabel_label.
657663
///
658664
/// In en, this message translates to:
659-
/// **'Additional text'**
660-
String get app_components_radioButton_radioButtonItem_additionalLabel_label;
665+
/// **'Extra label'**
666+
String get app_components_radioButton_radioButtonItem_extraLabel_label;
661667

662668
/// No description provided for @app_components_switch_label.
663669
///

app/lib/l10n/gen/ouds_flutter_app_localizations_ar.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ class AppLocalizationsAr extends AppLocalizations {
161161
@override
162162
String get app_components_common_error_label => 'خطأ';
163163

164+
@override
165+
String get app_components_common_error_message => 'رسالة خطأ';
166+
164167
@override
165168
String get app_components_common_layout_label => 'التخطيط';
166169

@@ -304,8 +307,8 @@ class AppLocalizationsAr extends AppLocalizations {
304307
'مُحَدَّد بخط';
305308

306309
@override
307-
String get app_components_radioButton_radioButtonItem_additionalLabel_label =>
308-
'نص إضافي';
310+
String get app_components_radioButton_radioButtonItem_extraLabel_label =>
311+
'تسمية اضافية';
309312

310313
@override
311314
String get app_components_switch_label => 'مفتاح التبديل';

app/lib/l10n/gen/ouds_flutter_app_localizations_en.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ class AppLocalizationsEn extends AppLocalizations {
161161
@override
162162
String get app_components_common_error_label => 'Error';
163163

164+
@override
165+
String get app_components_common_error_message => 'Error message';
166+
164167
@override
165168
String get app_components_common_layout_label => 'Layout';
166169

@@ -304,8 +307,8 @@ class AppLocalizationsEn extends AppLocalizations {
304307
'Outlined';
305308

306309
@override
307-
String get app_components_radioButton_radioButtonItem_additionalLabel_label =>
308-
'Additional text';
310+
String get app_components_radioButton_radioButtonItem_extraLabel_label =>
311+
'Extra label';
309312

310313
@override
311314
String get app_components_switch_label => 'Switch';

app/lib/l10n/ouds_flutter_ar.arb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"@_components": {},
5959
"app_components_common_color_label": "اللون",
6060
"app_components_common_error_label": "خطأ",
61+
"app_components_common_error_message": "رسالة خطأ",
6162
"app_components_common_layout_label": "التخطيط",
6263
"app_components_common_textOnlyLayout_label": "نص فقط",
6364
"app_components_common_iconAndTextLayout_label": "نص + أيقونة",
@@ -112,7 +113,7 @@
112113
"app_components_radioButton_radioButton_label": "زر الاختيار",
113114
"app_components_radioButton_radioButtonItem_label": "عنصر زر الاختيار",
114115
"app_components_radioButton_radioButtonItem_outlined_label": "مُحَدَّد بخط",
115-
"app_components_radioButton_radioButtonItem_additionalLabel_label": "نص إضافي",
116+
"app_components_radioButton_radioButtonItem_extraLabel_label": "تسمية اضافية",
116117

117118
"@_components_switch": {},
118119
"app_components_switch_label": "مفتاح التبديل",

app/lib/l10n/ouds_flutter_en.arb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
"@_components": {},
9595
"app_components_common_color_label": "Color",
9696
"app_components_common_error_label": "Error",
97+
"app_components_common_error_message": "Error message",
9798
"app_components_common_layout_label": "Layout",
9899
"app_components_common_textOnlyLayout_label": "Text only",
99100
"app_components_common_iconAndTextLayout_label": "Text + Icon",
@@ -148,7 +149,7 @@
148149
"app_components_radioButton_radioButton_label": "Radio button",
149150
"app_components_radioButton_radioButtonItem_label": "Radio Button Item",
150151
"app_components_radioButton_radioButtonItem_outlined_label": "Outlined",
151-
"app_components_radioButton_radioButtonItem_additionalLabel_label": "Additional text",
152+
"app_components_radioButton_radioButtonItem_extraLabel_label": "Extra label",
152153

153154
"@_components_switch": {},
154155
"app_components_switch_label": "Switch",

app/lib/ui/components/checkbox/checkbox_item_demo_screen.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ class _CheckboxItemDemoState extends State<_CheckboxItemDemo> {
166166
readOnly: customizationState!.hasReadOnly ? true : false,
167167
icon: customizationState!.hasIcon ? AppAssets.icons.functionalSocialAndEngagementHeartEmpty(themeController!) : null,
168168
isError: customizationState!.hasError ? true : false,
169+
errorText: ControlItemCustomizationUtils.getErrorMessageLabelText(customizationState!),
169170
divider: customizationState!.hasDivider ? true : false,
170171
tristate: widget.indeterminate,
171172
),
@@ -184,6 +185,7 @@ class _CheckboxItemDemoState extends State<_CheckboxItemDemo> {
184185
readOnly: customizationState!.hasReadOnly ? true : false,
185186
icon: customizationState!.hasIcon ? AppAssets.icons.functionalSocialAndEngagementHeartEmpty(themeController!) : null,
186187
isError: customizationState!.hasError ? true : false,
188+
errorText: ControlItemCustomizationUtils.getErrorMessageLabelText(customizationState!),
187189
divider: customizationState!.hasDivider ? true : false,
188190
tristate: widget.indeterminate,
189191
),
@@ -210,6 +212,7 @@ class _CheckboxItemDemoState extends State<_CheckboxItemDemo> {
210212
readOnly: customizationState!.hasReadOnly ? true : false,
211213
icon: customizationState!.hasIcon ? AppAssets.icons.functionalSocialAndEngagementHeartEmpty(themeController!) : null,
212214
isError: customizationState!.hasError ? true : false,
215+
errorText: ControlItemCustomizationUtils.getErrorMessageLabelText(customizationState!),
213216
divider: customizationState!.hasDivider ? true : false,
214217
tristate: widget.indeterminate,
215218
),
@@ -228,6 +231,7 @@ class _CheckboxItemDemoState extends State<_CheckboxItemDemo> {
228231
readOnly: customizationState!.hasReadOnly ? true : false,
229232
icon: customizationState!.hasIcon ? AppAssets.icons.functionalSocialAndEngagementHeartEmpty(themeController!) : null,
230233
isError: customizationState!.hasError ? true : false,
234+
errorText: ControlItemCustomizationUtils.getErrorMessageLabelText(customizationState!),
231235
divider: customizationState!.hasDivider ? true : false,
232236
tristate: widget.indeterminate,
233237
),
@@ -250,18 +254,21 @@ class _CustomizationContent extends StatefulWidget {
250254
class _CustomizationContentState extends State<_CustomizationContent> {
251255
late final FocusNode labelFocus;
252256
late final FocusNode descriptionFocus;
257+
late final FocusNode errorMessageFocus;
253258

254259
@override
255260
void initState() {
256261
super.initState();
257262
labelFocus = FocusNode();
258263
descriptionFocus = FocusNode();
264+
errorMessageFocus = FocusNode();
259265
}
260266

261267
@override
262268
void dispose() {
263269
labelFocus.dispose();
264270
descriptionFocus.dispose();
271+
errorMessageFocus.dispose();
265272
super.dispose();
266273
}
267274

@@ -343,6 +350,12 @@ class _CustomizationContentState extends State<_CustomizationContent> {
343350
focusNode: descriptionFocus,
344351
fieldType: FieldType.description,
345352
),
353+
CustomizableTextField(
354+
title: context.l10n.app_components_common_error_message,
355+
text: customizationState.errorMessageLabel,
356+
focusNode: errorMessageFocus,
357+
fieldType: FieldType.error,
358+
),
346359
],
347360
);
348361
}

app/lib/ui/components/control_item/control_item_code_generator.dart

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//
21
// Software Name: OUDS Flutter
32
// SPDX-FileCopyrightText: Copyright (c) Orange SA
43
// SPDX-License-Identifier: MIT
@@ -22,6 +21,29 @@ import 'package:ouds_flutter_demo/ui/components/control_item/control_item_enum.d
2221
/// rendering or previewing the checkbox with the selected properties.
2322
///
2423
class ControlItemCodeGenerator {
24+
// List to manage inclusion of elements
25+
static List<String> _includedElements = [
26+
'titleCode',
27+
'additionalTitleCode',
28+
'helperTitleCode',
29+
'reversedCode',
30+
'readOnlyCode',
31+
'iconCode',
32+
'errorCode',
33+
'errorMessageCode',
34+
'dividerCode',
35+
'outlinedCode',
36+
'tristateCode',
37+
'groupValueCode',
38+
'disableCode',
39+
'disableCodeRadio'
40+
];
41+
42+
// Method to set the inclusion list
43+
static void setIncludedElements(List<String> elements) {
44+
_includedElements = elements;
45+
}
46+
2547
// Static method to generate the code based on control item customization state
2648
static String updateCode(BuildContext context, bool indeterminate, ControlItemType control) {
2749
String value = 'isChecked';
@@ -41,17 +63,23 @@ class ControlItemCodeGenerator {
4163
value = 'isChecked';
4264
break;
4365
}
44-
return """$itemCode(
66+
67+
// Build the code string with conditional inclusion
68+
String code = """$itemCode(
4569
value: $value,${control == ControlItemType.radioButton ? groupValueCode(context) : ''}
4670
${control == ControlItemType.radioButton ? disableCodeRadio(context) : disableCode(context)}
47-
${titleCode(context)}${control == ControlItemType.radioButton ? additionalTitleCode(context) : ''}
48-
${helperTitleCode(context)}
49-
${reversedCode(context)}
50-
${readOnlyCode(context)}
51-
${iconCode(context)}
52-
${errorCode(context)}
53-
${dividerCode(context)}${control == ControlItemType.radioButton ? outlinedCode(context) : ''}${tristateCode(context, indeterminate)}
71+
${_includedElements.contains('titleCode') ? titleCode(context) : ''}
72+
${_includedElements.contains('additionalTitleCode') ? additionalTitleCode(context) : ''}
73+
${_includedElements.contains('helperTitleCode') ? helperTitleCode(context) : ''}
74+
${_includedElements.contains('reversedCode') ? reversedCode(context) : ''}
75+
${_includedElements.contains('readOnlyCode') ? readOnlyCode(context) : ''}
76+
${_includedElements.contains('iconCode') ? iconCode(context) : ''}
77+
${_includedElements.contains('errorCode') ? errorCode(context) : ''}
78+
${_includedElements.contains('errorMessageCode') ? errorMessageCode(context) : ''}
79+
${_includedElements.contains('dividerCode') ? dividerCode(context) : ''}${_includedElements.contains('outlinedCode') ? outlinedCode(context) : ''}${tristateCode(context, indeterminate)}
5480
);""";
81+
82+
return code;
5583
}
5684

5785
// Method to generate the disable code for the control item onChanged callback
@@ -73,7 +101,7 @@ ${dividerCode(context)}${control == ControlItemType.radioButton ? outlinedCode(c
73101
"});\n}" : 'null'},";
74102
}
75103

76-
// Method to generate the error code for the control item
104+
// Method to generate the group value code for radio buttons
77105
static String groupValueCode(BuildContext context) {
78106
return '\ngroupValue: selectedOption,';
79107
}
@@ -84,16 +112,22 @@ ${dividerCode(context)}${control == ControlItemType.radioButton ? outlinedCode(c
84112
return 'isError: ${customizationState?.hasError == true ? 'true' : 'false'},';
85113
}
86114

115+
// Method to generate the error message code for the control item
116+
static String errorMessageCode(BuildContext context) {
117+
final customizationState = ControlItemCustomization.of(context);
118+
return """errorText: '${customizationState?.errorMessageLabel}',""";
119+
}
120+
87121
// Method to generate the title code for the control item
88122
static String titleCode(BuildContext context) {
89123
final customizationState = ControlItemCustomization.of(context);
90124
return """title: '${customizationState?.labelText}',""";
91125
}
92126

93-
// Method to generate the helperTitle code for the control item
127+
// Method to generate the additional label code for the control item
94128
static String additionalTitleCode(BuildContext context) {
95129
final customizationState = ControlItemCustomization.of(context);
96-
return customizationState!.additionalLabelText.isEmpty ? '\nadditionalLabel: null,' : """additionalLabel: '${customizationState.additionalLabelText}',""";
130+
return customizationState!.additionalLabelText.isEmpty ? 'additionalLabel: null,' : """additionalLabel: '${customizationState.additionalLabelText}',""";
97131
}
98132

99133
// Method to generate the helperTitle code for the control item
@@ -126,7 +160,7 @@ ${dividerCode(context)}${control == ControlItemType.radioButton ? outlinedCode(c
126160
return "divider: ${customizationState?.hasDivider},";
127161
}
128162

129-
// Method to generate the divider code for the control item
163+
// Method to generate the outlined code for the control item
130164
static String outlinedCode(BuildContext context) {
131165
final customizationState = ControlItemCustomization.of(context);
132166
return "\noutlined: ${customizationState?.hasOutlined},";

app/lib/ui/components/control_item/control_item_customization.dart

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ class ControlItemCustomizationState extends CustomizationWidgetState<ControlItem
4343
late final InvertedState invertedState;
4444
late final LabelTextState labelTextState;
4545
late final AdditionalLabelTextState additionalLabelTextState;
46-
late final HelperLabelTextState helperLabelTextState;
46+
late final HelperLabelTextState descriptionTextLabelState;
47+
late final ErrorMessageLabelTextState errorMessageTextLabelState;
4748

4849
@override
4950
void initState() {
@@ -55,7 +56,8 @@ class ControlItemCustomizationState extends CustomizationWidgetState<ControlItem
5556
invertedState = InvertedState(setState);
5657
labelTextState = LabelTextState(setState);
5758
additionalLabelTextState = AdditionalLabelTextState(setState);
58-
helperLabelTextState = HelperLabelTextState(setState);
59+
descriptionTextLabelState = HelperLabelTextState(setState);
60+
errorMessageTextLabelState = ErrorMessageLabelTextState(setState);
5961
}
6062

6163
// Proxy getters and setters to expose the 'errorState' value directly.
@@ -87,8 +89,12 @@ class ControlItemCustomizationState extends CustomizationWidgetState<ControlItem
8789
set additionalLabelText(String value) => additionalLabelTextState.value = value;
8890

8991
// Proxy getters and setters to expose the 'helperLabelTextState' value directly.
90-
String get descriptionLabel => helperLabelTextState.value;
91-
set descriptionLabel(String value) => helperLabelTextState.value = value;
92+
String get descriptionLabel => descriptionTextLabelState.value;
93+
set descriptionLabel(String value) => descriptionTextLabelState.value = value;
94+
95+
// Proxy getters and setters to expose the 'helperLabelTextState' value directly.
96+
String get errorMessageLabel => errorMessageTextLabelState.value;
97+
set errorMessageLabel(String value) => errorMessageTextLabelState.value = value;
9298

9399
// Getter to determine if the 'Enabled' state should be disabled based on the current 'Error' state.
94100
bool get isEnabledWhenError {
@@ -277,6 +283,21 @@ class HelperLabelTextState {
277283
}
278284
}
279285

286+
/// MessageErrorLabelText State Management
287+
class ErrorMessageLabelTextState {
288+
ErrorMessageLabelTextState(this._setState);
289+
290+
final void Function(void Function()) _setState;
291+
String _messageErrorLabelTextValue = "";
292+
293+
String get value => _messageErrorLabelTextValue;
294+
set value(String newValue) {
295+
_setState(() {
296+
_messageErrorLabelTextValue = newValue;
297+
});
298+
}
299+
}
300+
280301
/// Class for handling error cases related to control item behavior.
281302
class CheckboxErrorCases {
282303
/// Determines if the 'Enabled' control item should be activated based on the 'hasError' parameter.

app/lib/ui/components/control_item/control_item_customization_utils.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,10 @@ class ControlItemCustomizationUtils {
3636
final label = customizationState.descriptionLabel;
3737
return label.isEmpty ? null : label;
3838
}
39+
40+
/// Retrieves the error message label text to display based on the current customization state.
41+
static String? getErrorMessageLabelText(ControlItemCustomizationState customizationState) {
42+
final label = customizationState.errorMessageLabel;
43+
return label.isEmpty ? null : label;
44+
}
3945
}

0 commit comments

Comments
 (0)