Merge pull request #10 from Iconica-Development/feature/id_and_onsubmit

feat: Multiple features added
This commit is contained in:
Gorter-dev 2022-10-26 09:15:25 +02:00 committed by GitHub
commit 39a09251c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 53 additions and 5 deletions

View file

@ -24,4 +24,9 @@
## 1.0.2 - October 13th 2022 ## 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: inputCheckWidget:
(String title, String? description, Function onPressed) { (String id, String title, String? description, Function onPressed) {
return GestureDetector( return GestureDetector(
onTap: () async { onTap: () async {
await onPressed(); await onPressed();

View file

@ -321,6 +321,7 @@ class _FlutterFormState extends ConsumerState<FlutterForm> {
if (widget.options.checkPage!.inputCheckWidget != null) { if (widget.options.checkPage!.inputCheckWidget != null) {
widgets.add( widgets.add(
widget.options.checkPage!.inputCheckWidget!( widget.options.checkPage!.inputCheckWidget!(
inputController.id ?? '',
inputController.checkPageTitle != null inputController.checkPageTitle != null
? inputController.checkPageTitle!(inputController.value) ? inputController.checkPageTitle!(inputController.value)
: inputController.value.toString(), : 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. /// [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. /// [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. /// [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. /// [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; 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. /// [onSaved] goes of when the save function is called for the page if [onValidate] return null.
void onSaved(T? value); void onSaved(T? value);

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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