From 6b3e29520624f925e7a63b2326db4086bd14116c Mon Sep 17 00:00:00 2001 From: Jacques Doeleman Date: Wed, 26 Oct 2022 09:00:24 +0200 Subject: [PATCH] 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. --- CHANGELOG.md | 7 ++++++- example/lib/example_pages/check_page.dart | 2 +- lib/src/form.dart | 1 + lib/src/widgets/input/abstractions.dart | 5 +++++ .../input/input_types/input_carousel/carousel_form.dart | 4 +++- .../input/input_types/input_carousel/input_carousel.dart | 8 ++++++++ .../input_types/input_date_picker/input_date_picker.dart | 3 +++ lib/src/widgets/input/input_types/input_email.dart | 4 ++++ .../input_number_picker/input_number_picker.dart | 3 +++ .../input/input_types/input_password/input_password.dart | 4 ++++ .../input/input_types/input_password/password.dart | 1 + lib/src/widgets/input/input_types/input_plain_text.dart | 7 ++++++- .../input/input_types/input_slider/input_slider.dart | 3 +++ .../input/input_types/input_switch/input_switch.dart | 3 +++ lib/utils/form.dart | 3 ++- 15 files changed, 53 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c29a36..31643f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,4 +24,9 @@ ## 1.0.2 - October 13th 2022 -- Added forgotten icon parameter on date input field and scrollpadding on text inputfield \ No newline at end of file +- 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. diff --git a/example/lib/example_pages/check_page.dart b/example/lib/example_pages/check_page.dart index 8dce2ff..bfad4f7 100644 --- a/example/lib/example_pages/check_page.dart +++ b/example/lib/example_pages/check_page.dart @@ -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(); diff --git a/lib/src/form.dart b/lib/src/form.dart index faceaa6..ac9d976 100644 --- a/lib/src/form.dart +++ b/lib/src/form.dart @@ -321,6 +321,7 @@ class _FlutterFormState extends ConsumerState { if (widget.options.checkPage!.inputCheckWidget != null) { widgets.add( widget.options.checkPage!.inputCheckWidget!( + inputController.id ?? '', inputController.checkPageTitle != null ? inputController.checkPageTitle!(inputController.value) : inputController.value.toString(), diff --git a/lib/src/widgets/input/abstractions.dart b/lib/src/widgets/input/abstractions.dart index 7f2908f..b6c7ddd 100644 --- a/lib/src/widgets/input/abstractions.dart +++ b/lib/src/widgets/input/abstractions.dart @@ -58,6 +58,8 @@ abstract class FlutterFormInputWidget 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 { /// [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); diff --git a/lib/src/widgets/input/input_types/input_carousel/carousel_form.dart b/lib/src/widgets/input/input_types/input_carousel/carousel_form.dart index d4ea6d9..ec063b4 100644 --- a/lib/src/widgets/input/input_types/input_carousel/carousel_form.dart +++ b/lib/src/widgets/input/input_types/input_carousel/carousel_form.dart @@ -7,9 +7,11 @@ class CarouselFormField extends FormField { required FormFieldSetter onSaved, required FormFieldValidator validator, void Function(int value)? onChanged, + void Function(int value)? onSubmit, int initialValue = 0, bool autovalidate = false, required List items, + double height = 425, }) : super( key: key, onSaved: onSaved, @@ -24,7 +26,7 @@ class CarouselFormField extends FormField { state.didChange(index); }, - height: 425, + height: height, aspectRatio: 2.0, enlargeCenterPage: true, enableInfiniteScroll: false, diff --git a/lib/src/widgets/input/input_types/input_carousel/input_carousel.dart b/lib/src/widgets/input/input_types/input_carousel/input_carousel.dart index de999b9..2fc82a0 100644 --- a/lib/src/widgets/input/input_types/input_carousel/input_carousel.dart +++ b/lib/src/widgets/input/input_types/input_carousel/input_carousel.dart @@ -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 { const FlutterFormInputCarousel({ Key? key, required FlutterFormInputController controller, Widget? label, required this.items, + this.height = 425, }) : super(key: key, controller: controller, label: label); final List items; + final double height; @override Widget build(BuildContext context, WidgetRef ref) { @@ -33,6 +37,7 @@ class FlutterFormInputCarousel extends FlutterFormInputWidget { 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; diff --git a/lib/src/widgets/input/input_types/input_date_picker/input_date_picker.dart b/lib/src/widgets/input/input_types/input_date_picker/input_date_picker.dart index 83637d7..4771df8 100644 --- a/lib/src/widgets/input/input_types/input_date_picker/input_date_picker.dart +++ b/lib/src/widgets/input/input_types/input_date_picker/input_date_picker.dart @@ -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; diff --git a/lib/src/widgets/input/input_types/input_email.dart b/lib/src/widgets/input/input_types/input_email.dart index 2ed9402..2460e9e 100644 --- a/lib/src/widgets/input/input_types/input_email.dart +++ b/lib/src/widgets/input/input_types/input_email.dart @@ -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; diff --git a/lib/src/widgets/input/input_types/input_number_picker/input_number_picker.dart b/lib/src/widgets/input/input_types/input_number_picker/input_number_picker.dart index 055f4b8..6b5f0ae 100644 --- a/lib/src/widgets/input/input_types/input_number_picker/input_number_picker.dart +++ b/lib/src/widgets/input/input_types/input_number_picker/input_number_picker.dart @@ -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; diff --git a/lib/src/widgets/input/input_types/input_password/input_password.dart b/lib/src/widgets/input/input_types/input_password/input_password.dart index a966e1c..c1300ba 100644 --- a/lib/src/widgets/input/input_types/input_password/input_password.dart +++ b/lib/src/widgets/input/input_types/input_password/input_password.dart @@ -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; diff --git a/lib/src/widgets/input/input_types/input_password/password.dart b/lib/src/widgets/input/input_types/input_password/password.dart index 5b93069..c9e1edc 100644 --- a/lib/src/widgets/input/input_types/input_password/password.dart +++ b/lib/src/widgets/input/input_types/input_password/password.dart @@ -33,6 +33,7 @@ class _PasswordTextFieldState extends ConsumerState { 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( diff --git a/lib/src/widgets/input/input_types/input_plain_text.dart b/lib/src/widgets/input/input_types/input_plain_text.dart index bc864c7..60abef4 100644 --- a/lib/src/widgets/input/input_types/input_plain_text.dart +++ b/lib/src/widgets/input/input_types/input_plain_text.dart @@ -15,7 +15,7 @@ class FlutterFormInputPlainText extends FlutterFormInputWidget { 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 { 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; diff --git a/lib/src/widgets/input/input_types/input_slider/input_slider.dart b/lib/src/widgets/input/input_types/input_slider/input_slider.dart index 025b3c3..7a233f2 100644 --- a/lib/src/widgets/input/input_types/input_slider/input_slider.dart +++ b/lib/src/widgets/input/input_types/input_slider/input_slider.dart @@ -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; diff --git a/lib/src/widgets/input/input_types/input_switch/input_switch.dart b/lib/src/widgets/input/input_types/input_switch/input_switch.dart index 2197ed3..01e8039 100644 --- a/lib/src/widgets/input/input_types/input_switch/input_switch.dart +++ b/lib/src/widgets/input/input_types/input_switch/input_switch.dart @@ -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; diff --git a/lib/utils/form.dart b/lib/utils/form.dart index f186237..ecf2dc5 100644 --- a/lib/utils/form.dart +++ b/lib/utils/form.dart @@ -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({