Skip to content

Commit 891267c

Browse files
committed
feat: add form date time & image conversion capabilities
1 parent 437b8ec commit 891267c

13 files changed

+621
-37
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
part of devspace;
3+
4+
// ignore: camel_case_types
5+
enum kFormInputDateTimeType
6+
{
7+
date,
8+
time,
9+
dateAndTime
10+
}
11+
12+
class FormInputDateTime extends FormInput {
13+
14+
final kFormInputDateTimeType type;
15+
16+
/// Defaults to 1900
17+
final DateTime? firstDate;
18+
19+
/// Defaults to 2100
20+
final DateTime? lastDate;
21+
/// If you want to display the date in a different format than the
22+
/// default, you can provide a function here.
23+
final String Function(DateTime? value)? toDisplayString;
24+
final String? hint;
25+
final void Function(DateTime? newValue)? onChange;
26+
27+
const FormInputDateTime({
28+
required super.id,
29+
super.initialValue,
30+
super.description,
31+
super.label,
32+
super.isOptional,
33+
super.isActive,
34+
this.type = kFormInputDateTimeType.date,
35+
this.firstDate,
36+
this.lastDate,
37+
this.toDisplayString,
38+
this.hint,
39+
this.onChange,
40+
});
41+
42+
}

lib/blue_forms/models/elements/form_input_images.dart

+17-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,22 @@ part of devspace;
55

66
class FormInputImagesFileSettings {
77

8-
const FormInputImagesFileSettings();
8+
final kImageConversionType conversion;
9+
final double conversionQuality;
10+
final int? maxWidth;
11+
final int? maxHeight;
12+
final int? minWidth;
13+
final int? minHeight;
14+
15+
const FormInputImagesFileSettings({
16+
this.conversion = kImageConversionType.none,
17+
this.conversionQuality = 1.0,
18+
this.maxWidth,
19+
this.maxHeight,
20+
this.minWidth,
21+
this.minHeight,
22+
});
23+
924

1025
}
1126

@@ -16,7 +31,7 @@ class FormInputImages extends FormInput {
1631
final int min;
1732
final int max;
1833
final FormInputImagesFileSettings fileSettings;
19-
final void Function(List<XFile> images)? onChange;
34+
final void Function(List<img.Image> images)? onChange;
2035

2136
const FormInputImages({
2237
required super.id,

lib/blue_forms/util/common_form_inputs.dart

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ abstract class CommonFormInputs {
7979
hint: LibStrings.lib_blueForms_commonInputs_passwordHint.tr(),
8080
autocorrect: false,
8181
isOptional: isOptional,
82+
trimOnSave: false,
8283
autofillHints: [AutofillHints.password],
8384
obscureText: true,
8485
enableSuggestions: false,

lib/blue_forms/widgets/form_element.dart

+14
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ class _FormElementWidget extends StatelessWidget {
5656
);
5757
}
5858

59+
if (definition is FormInputDateTime)
60+
{
61+
return _FormInputDateTimeWidget(
62+
key: Key(definition.id),
63+
definition: definition as FormInputDateTime,
64+
labelColor: labelColor,
65+
visuallyMarkRequired: visuallyMarkRequired,
66+
currentSavedValue: currentSavedValues[definition.id],
67+
externalError: externalErrors[definition.id],
68+
onSave: (value) => onSave(definition.id, value),
69+
onSubmitRequested: onSubmitRequested
70+
);
71+
}
72+
5973
if (definition is FormInputImages)
6074
{
6175
return _FormInputImagesWidget(

lib/blue_forms/widgets/form_group.dart

+7-7
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class _FormGroup extends StatelessWidget {
4343
{
4444
FormElement fiInputDefinition = definition.elements[i];
4545

46-
if (fiInputDefinition.isActive == false)
46+
if (fiInputDefinition.isActive == false && definition.elementsPerRow == 1)
4747
{
4848
continue;
4949
}
@@ -55,7 +55,7 @@ class _FormGroup extends StatelessWidget {
5555
{
5656
rowChildren.add(
5757
Expanded(
58-
child: _FormElementWidget(
58+
child: fiInputDefinition.isActive == false ? EmptyWidget() : _FormElementWidget(
5959
definition: fiInputDefinition,
6060
labelColor: labelColor,
6161
isFirstElement: isFirst,
@@ -93,12 +93,12 @@ class _FormGroup extends StatelessWidget {
9393
}
9494
}
9595

96+
// Note: normally this would be wrapped in an intrinsic height, but it
97+
// leads to problems if the async dependency is used in the form group
9698
groupChildren.add(
97-
IntrinsicHeight(
98-
child: Row(
99-
crossAxisAlignment: CrossAxisAlignment.stretch,
100-
children: rowChildren,
101-
),
99+
Row(
100+
crossAxisAlignment: CrossAxisAlignment.start,
101+
children: rowChildren,
102102
)
103103
);
104104
rowChildren = [];

lib/blue_forms/widgets/form_input_container.dart

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class _FormInputContainerWidget extends StatelessWidget {
3131
if (description != null) Padding(
3232
padding: context.paddingM_0.setTop(context.dimensions.spaceLValue),
3333
child: TextBody.medium(description!,
34-
textAlign: TextAlign.justify,
3534
italic: true,
3635
color: context.colors.onBackgroundLessFocus,
3736
),

0 commit comments

Comments
 (0)