Skip to content

Commit e29ad7a

Browse files
committed
feat: add background / surface setting to BlueForms
1 parent 4fae1dd commit e29ad7a

13 files changed

+65
-12
lines changed

lib/architect/plans/text_field/data.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ class TextFieldData extends PlanData {
2222
final bool autocorrect;
2323
final bool obscureText;
2424
final bool enableSuggestions;
25+
26+
/// The Textfield will assume it will be displayed on a surface, if it is
27+
/// displayed on a background, set this to true to adjust the colors accordingly.
28+
final bool onBackground;
2529
final TextInputType? textInputType;
2630
final ValueChanged<String>? onChanged;
2731
final ValueChanged<String?>? onSave;
@@ -50,6 +54,7 @@ class TextFieldData extends PlanData {
5054
this.autocorrect = true,
5155
this.obscureText = false,
5256
this.enableSuggestions = true,
57+
this.onBackground = false,
5358
this.textInputType,
5459
this.onChanged,
5560
this.onSave,

lib/architect/plans/text_field/default.regular.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class DefaultTextFieldRegular extends ArchBaseStatelessWidget<TextFieldData> {
121121
children: [
122122
TextLabel.small(
123123
data.label!,
124-
color: hasError ? context.colors.error : data.labelColor ?? context.colors.onBackgroundLessFocus,
124+
color: hasError ? context.colors.error : data.labelColor ?? (data.onBackground ? context.colors.onBackgroundLessFocus : context.colors.onSurfaceLessFocus),
125125
),
126126

127127
if (data.visuallyMarkAsRequired) TextLabel.small(

lib/blue_forms/blue_forms.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ class BlueForms extends StatefulWidget {
1111

1212
final VoidCallback? onCancel;
1313
final OnCompleteForms onComplete;
14+
/// BlueForms assume it will be displayed on a surface, if it is displayed on
15+
/// a background, set this to true to adjust the colors accordingly.
16+
final bool onBackground;
1417
final bool isLoading;
1518
final String? errorMessage;
1619
final FormError? error;
@@ -30,6 +33,7 @@ class BlueForms extends StatefulWidget {
3033
super.key,
3134
this.onCancel,
3235
required this.onComplete,
36+
this.onBackground = false,
3337
this.isLoading = false,
3438
this.error,
3539
this.errorMessage,
@@ -197,6 +201,7 @@ class _BlueFormsState extends State<BlueForms> {
197201
return _FormPageWidget(
198202
controller: page._controller!,
199203
definition: page,
204+
onBackground: widget.onBackground,
200205
labelColor: widget.labelColor,
201206
visuallyMarkRequiredFields: widget.visuallyMarkRequiredFields,
202207
currentSavedValues: _savedInputs,

lib/blue_forms/widgets/form_async_dependency.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class _FormAsyncDependency extends material.StatefulWidget {
99

1010
final FormAsyncDependency definition;
1111
final Color? labelColor;
12+
final bool onBackground;
1213
final bool isFirstElement;
1314
final bool isLastElement;
1415
final bool visuallyMarkRequired;
@@ -22,6 +23,7 @@ class _FormAsyncDependency extends material.StatefulWidget {
2223
super.key,
2324
required this.definition,
2425
this.labelColor,
26+
required this.onBackground,
2527
required this.isFirstElement,
2628
required this.isLastElement,
2729
required this.visuallyMarkRequired,
@@ -76,6 +78,7 @@ class _FormAsyncDependencyState extends material.State<_FormAsyncDependency> {
7678
key: key,
7779
definition: formElement,
7880
labelColor: widget.labelColor,
81+
onBackground: widget.onBackground,
7982
isFirstElement: widget.isFirstElement,
8083
isLastElement: widget.isLastElement,
8184
visuallyMarkRequired: widget.visuallyMarkRequired,

lib/blue_forms/widgets/form_element.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class _FormElementWidget extends StatelessWidget {
77

88
final FormElement definition;
99
final Color? labelColor;
10+
final bool onBackground;
1011
final bool isFirstElement;
1112
final bool isLastElement;
1213
final bool visuallyMarkRequired;
@@ -20,6 +21,7 @@ class _FormElementWidget extends StatelessWidget {
2021
super.key,
2122
required this.definition,
2223
this.labelColor,
24+
required this.onBackground,
2325
required this.isFirstElement,
2426
required this.isLastElement,
2527
required this.visuallyMarkRequired,
@@ -48,6 +50,7 @@ class _FormElementWidget extends StatelessWidget {
4850
key: Key(definition.id),
4951
definition: definition as FormInputText,
5052
labelColor: labelColor,
53+
onBackground: onBackground,
5154
visuallyMarkRequired: visuallyMarkRequired,
5255
currentSavedValue: currentSavedValues[definition.id],
5356
externalError: externalErrors[definition.id],
@@ -62,6 +65,7 @@ class _FormElementWidget extends StatelessWidget {
6265
key: Key(definition.id),
6366
definition: definition as FormInputDateTime,
6467
labelColor: labelColor,
68+
onBackground: onBackground,
6569
visuallyMarkRequired: visuallyMarkRequired,
6670
currentSavedValue: currentSavedValues[definition.id],
6771
externalError: externalErrors[definition.id],
@@ -76,6 +80,7 @@ class _FormElementWidget extends StatelessWidget {
7680
key: Key(definition.id),
7781
definition: definition as FormInputImages,
7882
labelColor: labelColor,
83+
onBackground: onBackground,
7984
visuallyMarkRequired: visuallyMarkRequired,
8085
currentSavedValue: currentSavedValues[definition.id],
8186
externalError: externalErrors[definition.id],
@@ -89,6 +94,7 @@ class _FormElementWidget extends StatelessWidget {
8994
key: Key(definition.id),
9095
definition: definition as FormInputPickOption,
9196
labelColor: labelColor,
97+
onBackground: onBackground,
9298
visuallyMarkRequired: visuallyMarkRequired,
9399
currentSavedValue: currentSavedValues[definition.id],
94100
externalError: externalErrors[definition.id],
@@ -101,6 +107,7 @@ class _FormElementWidget extends StatelessWidget {
101107
return _FormAsyncDependency(
102108
definition: definition as FormAsyncDependency,
103109
labelColor: labelColor,
110+
onBackground: onBackground,
104111
isFirstElement: isFirstElement,
105112
isLastElement: isLastElement,
106113
visuallyMarkRequired: visuallyMarkRequired,
@@ -116,6 +123,7 @@ class _FormElementWidget extends StatelessWidget {
116123
return _FormGroup(
117124
definition: definition as FormGroup,
118125
labelColor: labelColor,
126+
onBackground: onBackground,
119127
isFirstElement: isFirstElement,
120128
isLastElement: isLastElement,
121129
visuallyMarkRequired: visuallyMarkRequired,

lib/blue_forms/widgets/form_group.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class _FormGroup extends StatelessWidget {
99

1010
final FormGroup definition;
1111
final Color? labelColor;
12+
final bool onBackground;
1213
final bool isFirstElement;
1314
final bool isLastElement;
1415
final bool visuallyMarkRequired;
@@ -22,6 +23,7 @@ class _FormGroup extends StatelessWidget {
2223
super.key,
2324
required this.definition,
2425
this.labelColor,
26+
required this.onBackground,
2527
required this.isFirstElement,
2628
required this.isLastElement,
2729
required this.visuallyMarkRequired,
@@ -58,6 +60,7 @@ class _FormGroup extends StatelessWidget {
5860
child: fiInputDefinition.isActive == false ? EmptyWidget() : _FormElementWidget(
5961
definition: fiInputDefinition,
6062
labelColor: labelColor,
63+
onBackground: onBackground,
6164
isFirstElement: isFirst,
6265
isLastElement: isLast,
6366
visuallyMarkRequired: visuallyMarkRequired,
@@ -120,6 +123,7 @@ class _FormGroup extends StatelessWidget {
120123
_FormElementWidget(
121124
definition: fiInputDefinition,
122125
labelColor: labelColor,
126+
onBackground: onBackground,
123127
isFirstElement: isFirst,
124128
isLastElement: isLast,
125129
visuallyMarkRequired: visuallyMarkRequired,

lib/blue_forms/widgets/form_input_container.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class _FormInputContainerWidget extends StatelessWidget {
88

99
final String? description;
1010
final bool hasLabel;
11+
final bool onBackground;
1112
final List<FormElementButton> extraButtons;
1213
final Widget child;
1314

@@ -17,6 +18,7 @@ class _FormInputContainerWidget extends StatelessWidget {
1718
this.description,
1819
this.extraButtons = const [],
1920
required this.hasLabel,
21+
required this.onBackground,
2022
required this.child,
2123
});
2224

@@ -87,7 +89,7 @@ class _FormInputContainerWidget extends StatelessWidget {
8789
padding: context.paddingM_0.setTop(context.dimensions.spaceLValue),
8890
child: TextBody.medium(description!,
8991
italic: true,
90-
color: context.colors.onBackgroundLessFocus,
92+
color: onBackground ? context.colors.onBackgroundLessFocus : context.colors.onSurfaceLessFocus,
9193
),
9294
),
9395

lib/blue_forms/widgets/form_input_date_time.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class _FormInputDateTimeWidget extends material.StatefulWidget {
88

99
final FormInputDateTime definition;
1010
final Color? labelColor;
11+
final bool onBackground;
1112
final bool visuallyMarkRequired;
1213
final dynamic currentSavedValue;
1314
final String? externalError;
@@ -18,6 +19,7 @@ class _FormInputDateTimeWidget extends material.StatefulWidget {
1819
super.key,
1920
required this.definition,
2021
this.labelColor,
22+
required this.onBackground,
2123
required this.visuallyMarkRequired,
2224
required this.currentSavedValue,
2325
required this.onSave,
@@ -104,10 +106,12 @@ class _FormInputDateTimeWidgetState extends material.State<_FormInputDateTimeWid
104106
description: widget.definition.description,
105107
extraButtons: widget.definition.extraButtons,
106108
hasLabel: widget.definition.label != null,
109+
onBackground: widget.onBackground,
107110
child: TapDetector(
108111
onTap: _pickDateTime,
109112
child: _FakeTextField<DateTime>(
110113
labelColor: widget.labelColor,
114+
onBackground: widget.onBackground,
111115
visuallyMarkAsRequired: widget.visuallyMarkRequired && widget.definition.isOptional == false,
112116
label: widget.definition.label,
113117
hint: widget.definition.hint,
@@ -145,6 +149,7 @@ class _FakeTextField<T> extends material.StatefulWidget {
145149
final String? externalError;
146150
final String? label;
147151
final Color? labelColor;
152+
final bool onBackground;
148153
final bool visuallyMarkAsRequired;
149154
final String? hint;
150155
final String Function(T? value) toDisplayString;
@@ -156,6 +161,7 @@ class _FakeTextField<T> extends material.StatefulWidget {
156161
this.externalError,
157162
this.label,
158163
this.labelColor,
164+
required this.onBackground,
159165
this.hint,
160166
this.visuallyMarkAsRequired = false,
161167
required this.toDisplayString,
@@ -272,7 +278,7 @@ class _FakeTextFieldState<T> extends material.State<_FakeTextField<T>> {
272278
children: [
273279
TextLabel.small(
274280
widget.label!,
275-
color: hasError ? context.colors.error : widget.labelColor ?? context.colors.onBackgroundLessFocus,
281+
color: hasError ? context.colors.error : widget.labelColor ?? (widget.onBackground ? context.colors.onBackgroundLessFocus : context.colors.onSurfaceLessFocus),
276282
),
277283

278284
if (widget.visuallyMarkAsRequired) TextLabel.small(

lib/blue_forms/widgets/form_input_images.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class _FormInputImagesWidget extends StatelessWidget {
88

99
final FormInputImages definition;
1010
final Color? labelColor;
11+
final bool onBackground;
1112
final bool visuallyMarkRequired;
1213
final dynamic currentSavedValue;
1314
final String? externalError;
@@ -17,6 +18,7 @@ class _FormInputImagesWidget extends StatelessWidget {
1718
super.key,
1819
required this.definition,
1920
this.labelColor,
21+
required this.onBackground,
2022
required this.visuallyMarkRequired,
2123
required this.currentSavedValue,
2224
required this.onSave,
@@ -38,6 +40,7 @@ class _FormInputImagesWidget extends StatelessWidget {
3840
return _FormInputImagesWidgetSingle(
3941
definition: definition,
4042
labelColor: labelColor,
43+
onBackground: onBackground,
4144
visuallyMarkRequired: visuallyMarkRequired,
4245
currentSavedValue: currentSavedFile,
4346
onSave: (image) => onSave(image == null ? [] : [image]),
@@ -48,6 +51,7 @@ class _FormInputImagesWidget extends StatelessWidget {
4851
return _FormInputImagesWidgetMulti(
4952
definition: definition,
5053
labelColor: labelColor,
54+
onBackground: onBackground,
5155
visuallyMarkRequired: visuallyMarkRequired,
5256
currentSavedValue: currentSavedValue,
5357
onSave: onSave,
@@ -64,6 +68,7 @@ class _FormInputImagesWidgetMulti extends StatefulWidget {
6468

6569
final FormInputImages definition;
6670
final Color? labelColor;
71+
final bool onBackground;
6772
final bool visuallyMarkRequired;
6873
final dynamic currentSavedValue;
6974
final String? externalError;
@@ -74,6 +79,7 @@ class _FormInputImagesWidgetMulti extends StatefulWidget {
7479
super.key,
7580
required this.definition,
7681
required this.labelColor,
82+
required this.onBackground,
7783
required this.visuallyMarkRequired,
7884
required this.currentSavedValue,
7985
required this.onSave,
@@ -114,6 +120,7 @@ class _FormInputImagesWidgetMultiState extends State<_FormInputImagesWidgetMulti
114120
description: widget.definition.description,
115121
extraButtons: widget.definition.extraButtons,
116122
hasLabel: widget.definition.label != null,
123+
onBackground: widget.onBackground,
117124
child: Column(
118125
crossAxisAlignment: CrossAxisAlignment.start,
119126
mainAxisSize: MainAxisSize.min,

lib/blue_forms/widgets/form_input_images_single.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class _FormInputImagesWidgetSingle extends StatefulWidget {
1010

1111
final FormInputImages definition;
1212
final Color? labelColor;
13+
final bool onBackground;
1314
final bool visuallyMarkRequired;
1415
final dynamic currentSavedValue;
1516
final String? externalError;
@@ -20,6 +21,7 @@ class _FormInputImagesWidgetSingle extends StatefulWidget {
2021
super.key,
2122
required this.definition,
2223
this.labelColor,
24+
required this.onBackground,
2325
required this.visuallyMarkRequired,
2426
required this.currentSavedValue,
2527
required this.onSave,
@@ -126,6 +128,7 @@ class _FormInputImagesWidgetSingleState extends State<_FormInputImagesWidgetSing
126128
description: widget.definition.description,
127129
extraButtons: widget.definition.extraButtons,
128130
hasLabel: widget.definition.label != null,
131+
onBackground: widget.onBackground,
129132
child: FormField<Uint8List?>(
130133
initialValue: _getImageFromSavedOrInitialValue(),
131134
onSaved: widget.onSave,

lib/blue_forms/widgets/form_input_pick_option.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class _FormInputPickOptionWidget extends StatefulWidget {
99

1010
final FormInputPickOption definition;
1111
final Color? labelColor;
12+
final bool onBackground;
1213
final bool visuallyMarkRequired;
1314
final dynamic currentSavedValue;
1415
final String? externalError;
@@ -18,6 +19,7 @@ class _FormInputPickOptionWidget extends StatefulWidget {
1819
super.key,
1920
required this.definition,
2021
this.labelColor,
22+
required this.onBackground,
2123
required this.visuallyMarkRequired,
2224
required this.currentSavedValue,
2325
required this.onSave,
@@ -102,6 +104,7 @@ class _FormInputPickOptionWidgetState extends State<_FormInputPickOptionWidget>
102104
description: widget.definition.description,
103105
extraButtons: widget.definition.extraButtons,
104106
hasLabel: widget.definition.label != null,
107+
onBackground: widget.onBackground,
105108
child: Column(
106109
children: [
107110

@@ -127,7 +130,7 @@ class _FormInputPickOptionWidgetState extends State<_FormInputPickOptionWidget>
127130
Padding(
128131
padding: context.paddingM_0,
129132
child: TextBody.small(LibStrings.lib_blueForms_inputPickOption_pleaseChoose.tr(),
130-
color: context.colors.onBackgroundLessFocus,
133+
color: widget.onBackground ? context.colors.onBackgroundLessFocus : context.colors.onSurfaceLessFocus,
131134
),
132135
),
133136
);
@@ -228,7 +231,7 @@ class _FormInputPickOptionWidgetState extends State<_FormInputPickOptionWidget>
228231
if (!selected) context.spaceXXS,
229232

230233
TextBody.small(item.subtitle!,
231-
color: context.colors.onSurfaceLessFocus,
234+
color: !selected ? context.colors.onSurfaceLessFocus : (widget.onBackground ? context.colors.onBackgroundLessFocus : context.colors.onSurfaceLessFocus),
232235
italic: true,
233236
),
234237
],
@@ -239,8 +242,8 @@ class _FormInputPickOptionWidgetState extends State<_FormInputPickOptionWidget>
239242
{
240243
if (selected)
241244
{
242-
return TextBody.small(title,
243-
color: context.colors.onSurface,
245+
return TextLabel.small(title,
246+
color: widget.onBackground ? context.colors.onBackground : context.colors.onSurface,
244247
);
245248
}
246249

@@ -258,7 +261,7 @@ class _FormInputPickOptionWidgetState extends State<_FormInputPickOptionWidget>
258261
children: [
259262
TextLabel.small(
260263
widget.definition.label,
261-
color: hasError ? context.colors.error : widget.labelColor ?? context.colors.onBackgroundLessFocus,
264+
color: hasError ? context.colors.error : widget.labelColor ?? (widget.onBackground ? context.colors.onBackgroundLessFocus : context.colors.onSurfaceLessFocus),
262265
),
263266

264267
if (widget.visuallyMarkRequired && widget.definition.isRequired) TextLabel.small(

0 commit comments

Comments
 (0)