mirror of
https://github.com/Iconica-Development/flutter_form_wizard.git
synced 2025-05-19 19:03:47 +02:00
Added onChange to formInputControllers
This commit is contained in:
parent
9c76d2766a
commit
1eeaf65359
13 changed files with 86 additions and 72 deletions
|
@ -23,6 +23,7 @@ class _FormExampleState extends ConsumerState<FormExample> {
|
|||
checkPageTitle: (dynamic amount) {
|
||||
return "Age: $amount years";
|
||||
},
|
||||
onChanged: (value) => print(value),
|
||||
);
|
||||
|
||||
late final FlutterFormInputCarouselController carouselInputController;
|
||||
|
@ -49,6 +50,7 @@ class _FormExampleState extends ConsumerState<FormExample> {
|
|||
checkPageTitle: (dynamic firstName) {
|
||||
return "First Name: $firstName";
|
||||
},
|
||||
onChanged: (value) => print(value),
|
||||
);
|
||||
|
||||
FlutterFormInputPlainTextController lastNameController =
|
||||
|
@ -58,6 +60,7 @@ class _FormExampleState extends ConsumerState<FormExample> {
|
|||
checkPageTitle: (dynamic lastName) {
|
||||
return "Last Name: $lastName";
|
||||
},
|
||||
onChanged: (value) => print(value),
|
||||
);
|
||||
|
||||
@override
|
||||
|
@ -71,6 +74,7 @@ class _FormExampleState extends ConsumerState<FormExample> {
|
|||
checkPageDescription: (dynamic index) {
|
||||
return cars[index]["description"];
|
||||
},
|
||||
onChanged: (value) => print(value),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,13 +36,6 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.16.0"
|
||||
crypto:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: crypto
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.2"
|
||||
cupertino_icons:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -154,13 +147,6 @@ packages:
|
|||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.99"
|
||||
sliding_up_panel:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: sliding_up_panel
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0+1"
|
||||
source_span:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -210,20 +196,6 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.4.12"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: typed_data
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.3.1"
|
||||
uuid:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: uuid
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.6"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -10,7 +10,7 @@ import '/src/utils/formstate.dart' as fs;
|
|||
/// label is a standard parameter to normally sets the label of the input.
|
||||
///
|
||||
/// [registerController] should be called to register the given [controller] to the form page.
|
||||
abstract class FlutterFormInputWidget extends ConsumerWidget {
|
||||
abstract class FlutterFormInputWidget<T> extends ConsumerWidget {
|
||||
const FlutterFormInputWidget({
|
||||
Key? key,
|
||||
required this.controller,
|
||||
|
@ -19,7 +19,7 @@ abstract class FlutterFormInputWidget extends ConsumerWidget {
|
|||
}) : super(key: key);
|
||||
|
||||
/// The [controller] which determines how the value is handled and how the value is shown on the checkpage.
|
||||
final FlutterFormInputController controller;
|
||||
final FlutterFormInputController<T> controller;
|
||||
|
||||
/// [label] is a standard parameter to normally sets the label of the input.
|
||||
final Widget? label;
|
||||
|
@ -56,6 +56,8 @@ abstract class FlutterFormInputWidget extends ConsumerWidget {
|
|||
/// [checkPageDescription] is the same as checkPageTitle but for the description.
|
||||
/// If null no description will be shown.
|
||||
///
|
||||
/// [onChanged] can be set to get the value whenever the user changes it.
|
||||
///
|
||||
/// [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.
|
||||
|
@ -78,16 +80,19 @@ abstract class FlutterFormInputController<T> {
|
|||
/// return "$amount persons";
|
||||
/// },
|
||||
/// ```
|
||||
String Function(T value)? checkPageTitle;
|
||||
String Function(T? value)? checkPageTitle;
|
||||
|
||||
/// [checkPageDescription] is the same as checkPageTitle but for the description.
|
||||
/// If null no description will be shown.
|
||||
String Function(T value)? checkPageDescription;
|
||||
String Function(T? value)? checkPageDescription;
|
||||
|
||||
/// [onChanged] can be set to get the value whenever the user changes it.
|
||||
void Function(T? value)? onChanged;
|
||||
|
||||
/// [onSaved] goes of when the save function is called for the page if [onValidate] return null.
|
||||
void onSaved(T value);
|
||||
void onSaved(T? value);
|
||||
|
||||
/// [onValidate] is used to validate the given input by the user.
|
||||
String? onValidate(
|
||||
T value, String Function(String, {List<String>? params}) translator);
|
||||
T? value, String Function(String, {List<String>? params}) translator);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ class CarouselFormField extends FormField<int> {
|
|||
Key? key,
|
||||
required FormFieldSetter<int> onSaved,
|
||||
required FormFieldValidator<int> validator,
|
||||
void Function(int value)? onChanged,
|
||||
int initialValue = 0,
|
||||
bool autovalidate = false,
|
||||
required List<Widget> items,
|
||||
|
@ -19,6 +20,8 @@ class CarouselFormField extends FormField<int> {
|
|||
options: CarouselOptions(
|
||||
initialPage: initialValue,
|
||||
onPageChanged: (index, reason) {
|
||||
onChanged?.call(index);
|
||||
|
||||
state.didChange(index);
|
||||
},
|
||||
height: 425,
|
||||
|
|
|
@ -10,10 +10,10 @@ import 'carousel_form.dart';
|
|||
/// [items] will be the [Widget]s to be displayed in the carousel.
|
||||
///
|
||||
/// Standard controller is [FlutterFormInputCarouselController].
|
||||
class FlutterFormInputCarousel extends FlutterFormInputWidget {
|
||||
class FlutterFormInputCarousel extends FlutterFormInputWidget<int> {
|
||||
const FlutterFormInputCarousel({
|
||||
Key? key,
|
||||
required FlutterFormInputController controller,
|
||||
required FlutterFormInputController<int> controller,
|
||||
Widget? label,
|
||||
required this.items,
|
||||
}) : super(key: key, controller: controller, label: label);
|
||||
|
@ -30,6 +30,7 @@ class FlutterFormInputCarousel extends FlutterFormInputWidget {
|
|||
return CarouselFormField(
|
||||
onSaved: (value) => controller.onSaved(value),
|
||||
validator: (value) => controller.onValidate(value, _),
|
||||
onChanged: controller.onChanged,
|
||||
initialValue: controller.value ?? 0,
|
||||
items: items,
|
||||
);
|
||||
|
@ -47,6 +48,7 @@ class FlutterFormInputCarouselController
|
|||
this.value,
|
||||
this.checkPageTitle,
|
||||
this.checkPageDescription,
|
||||
this.onChanged,
|
||||
});
|
||||
|
||||
@override
|
||||
|
@ -59,19 +61,22 @@ class FlutterFormInputCarouselController
|
|||
bool mandatory;
|
||||
|
||||
@override
|
||||
String Function(int value)? checkPageTitle;
|
||||
String Function(int? value)? checkPageTitle;
|
||||
|
||||
@override
|
||||
String Function(int value)? checkPageDescription;
|
||||
String Function(int? value)? checkPageDescription;
|
||||
|
||||
@override
|
||||
void onSaved(int value) {
|
||||
void Function(int? value)? onChanged;
|
||||
|
||||
@override
|
||||
void onSaved(int? value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@override
|
||||
String? onValidate(
|
||||
int value, String Function(String, {List<String>? params}) translator) {
|
||||
int? value, String Function(String, {List<String>? params}) translator) {
|
||||
if (mandatory) {}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -7,10 +7,10 @@ import '../../../../flutter_form.dart';
|
|||
/// Input for an email used in a [FlutterForm].
|
||||
///
|
||||
/// Standard controller is [FlutterFormInputEmailController].
|
||||
class FlutterFormInputEmail extends FlutterFormInputWidget {
|
||||
class FlutterFormInputEmail extends FlutterFormInputWidget<String> {
|
||||
const FlutterFormInputEmail({
|
||||
Key? key,
|
||||
required FlutterFormInputController controller,
|
||||
required FlutterFormInputController<String> controller,
|
||||
Widget? label,
|
||||
}) : super(
|
||||
key: key,
|
||||
|
@ -31,6 +31,7 @@ class FlutterFormInputEmail extends FlutterFormInputWidget {
|
|||
controller.onSaved(value);
|
||||
},
|
||||
validator: (value) => controller.onValidate(value, _),
|
||||
onChanged: (value) => controller.onChanged?.call(value),
|
||||
decoration: InputDecoration(
|
||||
focusColor: Theme.of(context).primaryColor,
|
||||
label: label ?? const Text("Email"),
|
||||
|
@ -50,6 +51,7 @@ class FlutterFormInputEmailController
|
|||
this.value,
|
||||
this.checkPageTitle,
|
||||
this.checkPageDescription,
|
||||
this.onChanged,
|
||||
});
|
||||
|
||||
@override
|
||||
|
@ -62,10 +64,13 @@ class FlutterFormInputEmailController
|
|||
bool mandatory;
|
||||
|
||||
@override
|
||||
String Function(String value)? checkPageTitle;
|
||||
String Function(String? value)? checkPageTitle;
|
||||
|
||||
@override
|
||||
String Function(String value)? checkPageDescription;
|
||||
String Function(String? value)? checkPageDescription;
|
||||
|
||||
@override
|
||||
void Function(String? value)? onChanged;
|
||||
|
||||
@override
|
||||
void onSaved(dynamic value) {
|
||||
|
|
|
@ -11,10 +11,10 @@ import 'numberpicker.dart';
|
|||
/// [maxValue] sets the maximal value of the picker.
|
||||
///
|
||||
/// Standard controller is [FlutterFormInputNumberPickerController].
|
||||
class FlutterFormInputNumberPicker extends FlutterFormInputWidget {
|
||||
class FlutterFormInputNumberPicker extends FlutterFormInputWidget<int> {
|
||||
const FlutterFormInputNumberPicker({
|
||||
Key? key,
|
||||
required FlutterFormInputController controller,
|
||||
required FlutterFormInputController<int> controller,
|
||||
Widget? label,
|
||||
this.minValue = 0,
|
||||
this.maxValue = 100,
|
||||
|
@ -34,10 +34,9 @@ class FlutterFormInputNumberPicker extends FlutterFormInputWidget {
|
|||
return NumberPickerFormField(
|
||||
minValue: minValue,
|
||||
maxValue: maxValue,
|
||||
onSaved: (value) {
|
||||
controller.onSaved(value);
|
||||
},
|
||||
onSaved: (value) => controller.onSaved(value),
|
||||
validator: (value) => controller.onValidate(value, _),
|
||||
onChanged: (value) => controller.onChanged?.call(value),
|
||||
initialValue: controller.value ?? minValue,
|
||||
);
|
||||
}
|
||||
|
@ -51,6 +50,7 @@ class NumberPickerFormField extends FormField<int> {
|
|||
Key? key,
|
||||
required FormFieldSetter<int> onSaved,
|
||||
required FormFieldValidator<int> validator,
|
||||
void Function(int value)? onChanged,
|
||||
int initialValue = 0,
|
||||
bool autovalidate = false,
|
||||
int minValue = 0,
|
||||
|
@ -66,6 +66,8 @@ class NumberPickerFormField extends FormField<int> {
|
|||
maxValue: maxValue,
|
||||
value: initialValue,
|
||||
onChanged: (int value) {
|
||||
onChanged?.call(value);
|
||||
|
||||
state.didChange(value);
|
||||
},
|
||||
itemHeight: 35,
|
||||
|
@ -82,6 +84,7 @@ class FlutterFormInputNumberPickerController
|
|||
this.value,
|
||||
this.checkPageTitle,
|
||||
this.checkPageDescription,
|
||||
this.onChanged,
|
||||
});
|
||||
|
||||
@override
|
||||
|
@ -94,19 +97,22 @@ class FlutterFormInputNumberPickerController
|
|||
bool mandatory;
|
||||
|
||||
@override
|
||||
String Function(int value)? checkPageTitle;
|
||||
String Function(int? value)? checkPageTitle;
|
||||
|
||||
@override
|
||||
String Function(int value)? checkPageDescription;
|
||||
String Function(int? value)? checkPageDescription;
|
||||
|
||||
@override
|
||||
void onSaved(int value) {
|
||||
void Function(int? value)? onChanged;
|
||||
|
||||
@override
|
||||
void onSaved(int? value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@override
|
||||
String? onValidate(
|
||||
int value, String Function(String, {List<String>? params}) translator) {
|
||||
int? value, String Function(String, {List<String>? params}) translator) {
|
||||
if (mandatory) {}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -6,10 +6,10 @@ import '../../../../../flutter_form.dart';
|
|||
/// Input for a password used in a [FlutterForm].
|
||||
///
|
||||
/// Standard controller is [FlutterFormInputEmailController].
|
||||
class FlutterFormInputPassword extends FlutterFormInputWidget {
|
||||
class FlutterFormInputPassword extends FlutterFormInputWidget<String> {
|
||||
const FlutterFormInputPassword({
|
||||
Key? key,
|
||||
required FlutterFormInputController controller,
|
||||
required FlutterFormInputController<String> controller,
|
||||
Widget? label,
|
||||
}) : super(key: key, controller: controller, label: label);
|
||||
|
||||
|
@ -35,6 +35,7 @@ class FlutterFormInputPasswordController
|
|||
this.value,
|
||||
this.checkPageTitle,
|
||||
this.checkPageDescription,
|
||||
this.onChanged,
|
||||
});
|
||||
|
||||
@override
|
||||
|
@ -47,10 +48,13 @@ class FlutterFormInputPasswordController
|
|||
bool mandatory;
|
||||
|
||||
@override
|
||||
String Function(String value)? checkPageTitle;
|
||||
String Function(String? value)? checkPageTitle;
|
||||
|
||||
@override
|
||||
String Function(String value)? checkPageDescription;
|
||||
String Function(String? value)? checkPageDescription;
|
||||
|
||||
@override
|
||||
void Function(String? value)? onChanged;
|
||||
|
||||
@override
|
||||
void onSaved(dynamic value) {
|
||||
|
|
|
@ -32,6 +32,7 @@ class _PasswordTextFieldState extends ConsumerState<PasswordTextField> {
|
|||
obscureText: obscured,
|
||||
onSaved: (value) => widget.controller.onSaved(value),
|
||||
validator: (value) => widget.controller.onValidate(value, _),
|
||||
onChanged: (value) => widget.controller.onChanged?.call(value),
|
||||
decoration: InputDecoration(
|
||||
label: widget.label ?? const Text("Password"),
|
||||
suffixIcon: IconButton(
|
||||
|
|
|
@ -7,10 +7,10 @@ import '../../../../flutter_form.dart';
|
|||
/// Input for plain text input used in a [FlutterForm].
|
||||
///
|
||||
/// Standard controller is [FlutterFormInputPlainTextController].
|
||||
class FlutterFormInputPlainText extends FlutterFormInputWidget {
|
||||
class FlutterFormInputPlainText extends FlutterFormInputWidget<String> {
|
||||
const FlutterFormInputPlainText({
|
||||
Key? key,
|
||||
required FlutterFormInputController controller,
|
||||
required FlutterFormInputController<String> controller,
|
||||
Widget? label,
|
||||
this.decoration,
|
||||
this.textAlignVertical,
|
||||
|
@ -41,6 +41,7 @@ class FlutterFormInputPlainText extends FlutterFormInputWidget {
|
|||
initialValue: controller.value,
|
||||
onSaved: (value) => controller.onSaved(value),
|
||||
validator: (value) => controller.onValidate(value, _),
|
||||
onChanged: (value) => controller.onChanged?.call(value),
|
||||
decoration: inputDecoration,
|
||||
textAlignVertical: textAlignVertical,
|
||||
expands: expands,
|
||||
|
@ -66,7 +67,7 @@ class FlutterFormInputMultiLine extends StatelessWidget {
|
|||
this.maxCharacters,
|
||||
}) : super(key: key);
|
||||
|
||||
final FlutterFormInputController controller;
|
||||
final FlutterFormInputController<String> controller;
|
||||
final Widget? label;
|
||||
|
||||
final String? hint;
|
||||
|
@ -114,6 +115,7 @@ class FlutterFormInputPlainTextController
|
|||
this.value,
|
||||
this.checkPageTitle,
|
||||
this.checkPageDescription,
|
||||
this.onChanged,
|
||||
});
|
||||
|
||||
@override
|
||||
|
@ -126,13 +128,16 @@ class FlutterFormInputPlainTextController
|
|||
bool mandatory;
|
||||
|
||||
@override
|
||||
String Function(String value)? checkPageTitle;
|
||||
String Function(String? value)? checkPageTitle;
|
||||
|
||||
@override
|
||||
String Function(String value)? checkPageDescription;
|
||||
String Function(String? value)? checkPageDescription;
|
||||
|
||||
@override
|
||||
void onSaved(String value) {
|
||||
void Function(String? value)? onChanged;
|
||||
|
||||
@override
|
||||
void onSaved(String? value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,10 +8,10 @@ import '../../../../../flutter_form.dart';
|
|||
/// Input for a number value between two values via a slider. Used in a [FlutterForm].
|
||||
///
|
||||
/// Standard controller is [FlutterFormInputSliderController].
|
||||
class FlutterFormInputSlider extends FlutterFormInputWidget {
|
||||
class FlutterFormInputSlider extends FlutterFormInputWidget<double> {
|
||||
const FlutterFormInputSlider({
|
||||
Key? key,
|
||||
required FlutterFormInputController controller,
|
||||
required FlutterFormInputController<double> controller,
|
||||
Widget? label,
|
||||
this.minValue = 0,
|
||||
this.maxValue = 100,
|
||||
|
@ -46,6 +46,7 @@ class FlutterFormInputSliderController
|
|||
this.value,
|
||||
this.checkPageTitle,
|
||||
this.checkPageDescription,
|
||||
this.onChanged,
|
||||
});
|
||||
|
||||
@override
|
||||
|
@ -58,18 +59,21 @@ class FlutterFormInputSliderController
|
|||
bool mandatory;
|
||||
|
||||
@override
|
||||
String Function(double value)? checkPageTitle;
|
||||
String Function(double? value)? checkPageTitle;
|
||||
|
||||
@override
|
||||
String Function(double value)? checkPageDescription;
|
||||
String Function(double? value)? checkPageDescription;
|
||||
|
||||
@override
|
||||
void onSaved(double value) {
|
||||
void Function(double? value)? onChanged;
|
||||
|
||||
@override
|
||||
void onSaved(double? value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@override
|
||||
String? onValidate(double value,
|
||||
String? onValidate(double? value,
|
||||
String Function(String, {List<String>? params}) translator) {
|
||||
if (mandatory) {}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ class SliderFormField extends FormField<double> {
|
|||
Key? key,
|
||||
required FormFieldSetter<double> onSaved,
|
||||
required FormFieldValidator<double> validator,
|
||||
void Function(double value)? onChanged,
|
||||
double initialValue = 0.5,
|
||||
}) : super(
|
||||
key: key,
|
||||
|
@ -16,6 +17,8 @@ class SliderFormField extends FormField<double> {
|
|||
return Slider(
|
||||
value: state.value ?? initialValue,
|
||||
onChanged: (double value) {
|
||||
onChanged?.call(value);
|
||||
|
||||
state.didChange(value);
|
||||
},
|
||||
);
|
||||
|
|
|
@ -17,9 +17,6 @@ dependencies:
|
|||
flutter_riverpod: ^1.0.4
|
||||
localization: ^2.1.0
|
||||
|
||||
sliding_up_panel: ^2.0.0+1
|
||||
uuid: ^3.0.6
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
|
|
Loading…
Reference in a new issue