feat: Multiple features added

The input check widget callback now has an id of the inputfield.
The ability to set the height of the carousel input field.
Some inputcontroller have an onsubmit of the  inputfield supports it.
This commit is contained in:
Jacques Doeleman 2022-10-26 09:00:24 +02:00
parent 3ed774bebb
commit 6b3e295206
15 changed files with 53 additions and 5 deletions

View file

@ -24,4 +24,9 @@
## 1.0.2 - October 13th 2022
- Added forgotten icon parameter on date input field and scrollpadding on text inputfield
- Added forgotten icon parameter on date input field and scrollpadding on text inputfield
## 2.0.0 - October 26th 2022
- Added the id of the input field on the input check widget.
- Ability to set the height of the carousel input field.
- InputController now contains the onSubmit callback.

View file

@ -24,7 +24,7 @@ class CheckPageExample {
),
),
inputCheckWidget:
(String title, String? description, Function onPressed) {
(String id, String title, String? description, Function onPressed) {
return GestureDetector(
onTap: () async {
await onPressed();

View file

@ -321,6 +321,7 @@ class _FlutterFormState extends ConsumerState<FlutterForm> {
if (widget.options.checkPage!.inputCheckWidget != null) {
widgets.add(
widget.options.checkPage!.inputCheckWidget!(
inputController.id ?? '',
inputController.checkPageTitle != null
? inputController.checkPageTitle!(inputController.value)
: inputController.value.toString(),

View file

@ -58,6 +58,8 @@ abstract class FlutterFormInputWidget<T> extends ConsumerWidget {
///
/// [onChanged] can be set to get the value whenever the user changes it. Should not be used to save the value.
///
/// [onSubmit] can be set to get the value whenever the user submits it. Should not be used to save the value.
///
/// [onSaved] goes of when the save function is called for the page if [onValidate] return null.
///
/// [onValidate] is used to validate the given input by the user.
@ -89,6 +91,9 @@ abstract class FlutterFormInputController<T> {
/// [onChanged] can be set to get the value whenever the user changes it. Should not be used to save the value.
void Function(T? value)? onChanged;
/// [onSubmit] can be set to get the value whenever the user submits it. Should not be used to save the value.
void Function(T? value)? onSubmit;
/// [onSaved] goes of when the save function is called for the page if [onValidate] return null.
void onSaved(T? value);

View file

@ -7,9 +7,11 @@ class CarouselFormField extends FormField<int> {
required FormFieldSetter<int> onSaved,
required FormFieldValidator<int> validator,
void Function(int value)? onChanged,
void Function(int value)? onSubmit,
int initialValue = 0,
bool autovalidate = false,
required List<Widget> items,
double height = 425,
}) : super(
key: key,
onSaved: onSaved,
@ -24,7 +26,7 @@ class CarouselFormField extends FormField<int> {
state.didChange(index);
},
height: 425,
height: height,
aspectRatio: 2.0,
enlargeCenterPage: true,
enableInfiniteScroll: false,

View file

@ -10,15 +10,19 @@ import 'carousel_form.dart';
/// [items] will be the [Widget]s to be displayed in the carousel.
///
/// Standard controller is [FlutterFormInputCarouselController].
///
/// Height sets the height of the inputfield. Default to 425.
class FlutterFormInputCarousel extends FlutterFormInputWidget<int> {
const FlutterFormInputCarousel({
Key? key,
required FlutterFormInputController<int> controller,
Widget? label,
required this.items,
this.height = 425,
}) : super(key: key, controller: controller, label: label);
final List<Widget> items;
final double height;
@override
Widget build(BuildContext context, WidgetRef ref) {
@ -33,6 +37,7 @@ class FlutterFormInputCarousel extends FlutterFormInputWidget<int> {
onChanged: controller.onChanged,
initialValue: controller.value ?? 0,
items: items,
height: height,
);
}
}
@ -69,6 +74,9 @@ class FlutterFormInputCarouselController
@override
void Function(int? value)? onChanged;
@override
void Function(int? value)? onSubmit;
@override
void onSaved(int? value) {
this.value = value;

View file

@ -105,6 +105,9 @@ class FlutterFormInputDateTimeController
@override
void Function(String? value)? onChanged;
@override
void Function(String? value)? onSubmit;
@override
void onSaved(dynamic value) {
this.value = value;

View file

@ -52,6 +52,7 @@ class FlutterFormInputEmailController
this.checkPageTitle,
this.checkPageDescription,
this.onChanged,
this.onSubmit,
});
@override
@ -72,6 +73,9 @@ class FlutterFormInputEmailController
@override
void Function(String? value)? onChanged;
@override
void Function(String? value)? onSubmit;
@override
void onSaved(dynamic value) {
this.value = value;

View file

@ -105,6 +105,9 @@ class FlutterFormInputNumberPickerController
@override
void Function(int? value)? onChanged;
@override
void Function(int? value)? onSubmit;
@override
void onSaved(int? value) {
this.value = value;

View file

@ -36,6 +36,7 @@ class FlutterFormInputPasswordController
this.checkPageTitle,
this.checkPageDescription,
this.onChanged,
this.onSubmit,
});
@override
@ -56,6 +57,9 @@ class FlutterFormInputPasswordController
@override
void Function(String? value)? onChanged;
@override
void Function(String? value)? onSubmit;
@override
void onSaved(dynamic value) {
this.value = value;

View file

@ -33,6 +33,7 @@ class _PasswordTextFieldState extends ConsumerState<PasswordTextField> {
onSaved: (value) => widget.controller.onSaved(value),
validator: (value) => widget.controller.onValidate(value, _),
onChanged: (value) => widget.controller.onChanged?.call(value),
onFieldSubmitted: (value) => widget.controller.onSubmit?.call(value),
decoration: InputDecoration(
label: widget.label ?? const Text("Password"),
suffixIcon: IconButton(

View file

@ -15,7 +15,7 @@ class FlutterFormInputPlainText extends FlutterFormInputWidget<String> {
this.decoration,
this.textAlignVertical,
this.expands = false,
this.maxLines,
this.maxLines = 1,
this.scrollPadding,
this.maxLength,
}) : super(key: key, controller: controller, label: label);
@ -45,6 +45,7 @@ class FlutterFormInputPlainText extends FlutterFormInputWidget<String> {
onSaved: (value) => controller.onSaved(value),
validator: (value) => controller.onValidate(value, _),
onChanged: (value) => controller.onChanged?.call(value),
onFieldSubmitted: (value) => controller.onSubmit?.call(value),
decoration: inputDecoration,
textAlignVertical: textAlignVertical,
expands: expands,
@ -119,6 +120,7 @@ class FlutterFormInputPlainTextController
this.checkPageTitle,
this.checkPageDescription,
this.onChanged,
this.onSubmit,
});
@override
@ -139,6 +141,9 @@ class FlutterFormInputPlainTextController
@override
void Function(String? value)? onChanged;
@override
void Function(String? value)? onSubmit;
@override
void onSaved(String? value) {
this.value = value;

View file

@ -67,6 +67,9 @@ class FlutterFormInputSliderController
@override
void Function(double? value)? onChanged;
@override
void Function(double? value)? onSubmit;
@override
void onSaved(double? value) {
this.value = value;

View file

@ -63,6 +63,9 @@ class FlutterFormInputSwitchController
@override
void Function(bool? value)? onChanged;
@override
void Function(bool? value)? onSubmit;
@override
void onSaved(bool? value) {
this.value = value;

View file

@ -69,7 +69,8 @@ class FlutterFormPage {
class CheckPage {
final Widget? title;
final MainAxisAlignment mainAxisAlignment;
final Widget Function(String title, String? description, Function onPressed)?
final Widget Function(
String id, String title, String? description, Function onPressed)?
inputCheckWidget;
const CheckPage({