mirror of
https://github.com/Iconica-Development/flutter_form_wizard.git
synced 2025-05-19 19:03:47 +02:00
Merge pull request #5 from Iconica-Development/feature/onChange
Added onChange to formInputControllers
This commit is contained in:
commit
80fa91852f
18 changed files with 227 additions and 73 deletions
|
@ -11,3 +11,9 @@
|
|||
## 0.2.0 - October 13th 2022
|
||||
|
||||
- Added date input widget
|
||||
|
||||
## 1.0.0 - October 13th 2022
|
||||
|
||||
- Fix: Proper use of generics
|
||||
- Inputcontrollers now have an onChange.
|
||||
- Added switch input field
|
||||
|
|
|
@ -25,6 +25,7 @@ class _FormExampleState extends ConsumerState<FormExample> {
|
|||
checkPageTitle: (dynamic amount) {
|
||||
return "Age: $amount years";
|
||||
},
|
||||
onChanged: (value) => debugPrint(value.toString()),
|
||||
);
|
||||
|
||||
late final FlutterFormInputCarouselController carouselInputController;
|
||||
|
@ -51,6 +52,7 @@ class _FormExampleState extends ConsumerState<FormExample> {
|
|||
checkPageTitle: (dynamic firstName) {
|
||||
return "First Name: $firstName";
|
||||
},
|
||||
onChanged: (value) => debugPrint(value),
|
||||
);
|
||||
|
||||
FlutterFormInputPlainTextController lastNameController =
|
||||
|
@ -60,6 +62,7 @@ class _FormExampleState extends ConsumerState<FormExample> {
|
|||
checkPageTitle: (dynamic lastName) {
|
||||
return "Last Name: $lastName";
|
||||
},
|
||||
onChanged: (value) => debugPrint(value),
|
||||
);
|
||||
|
||||
FlutterFormInputPlainTextController dateController =
|
||||
|
@ -82,6 +85,7 @@ class _FormExampleState extends ConsumerState<FormExample> {
|
|||
checkPageDescription: (dynamic index) {
|
||||
return cars[index]["description"];
|
||||
},
|
||||
onChanged: (value) => debugPrint(value.toString()),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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. 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.
|
||||
|
@ -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. Should not be used to save the value.
|
||||
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;
|
||||
|
|
|
@ -84,10 +84,13 @@ class FlutterFormInputDateTimeController
|
|||
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) {
|
||||
|
|
|
@ -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);
|
||||
},
|
||||
);
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_form/flutter_form.dart';
|
||||
import 'package:flutter_form/src/widgets/input/input_types/input_switch/input_switch_field.dart';
|
||||
import 'package:flutter_form/utils/translation_service.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
/// Input for a boolean switch. Used in a [FlutterForm].
|
||||
///
|
||||
/// Standard controller is [FlutterFormInputSwitchController].
|
||||
class FlutterFormInputSwitch extends FlutterFormInputWidget<bool> {
|
||||
const FlutterFormInputSwitch({
|
||||
Key? key,
|
||||
required FlutterFormInputController<bool> controller,
|
||||
Widget? label,
|
||||
}) : super(key: key, controller: controller, label: label);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
String Function(String, {List<String>? params}) _ =
|
||||
getTranslator(context, ref);
|
||||
|
||||
super.registerController(context);
|
||||
|
||||
return SwitchFormField(
|
||||
onSaved: (value) {
|
||||
controller.onSaved(value);
|
||||
},
|
||||
validator: (value) => controller.onValidate(value, _),
|
||||
initialValue: controller.value ?? false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Controller for the switch used by a [FlutterFormInputWidget] used in a [FlutterForm].
|
||||
///
|
||||
/// Mainly used by [FlutterFormInputSwitch].
|
||||
class FlutterFormInputSwitchController
|
||||
implements FlutterFormInputController<bool> {
|
||||
FlutterFormInputSwitchController({
|
||||
required this.id,
|
||||
this.mandatory = true,
|
||||
this.value,
|
||||
this.checkPageTitle,
|
||||
this.checkPageDescription,
|
||||
this.onChanged,
|
||||
});
|
||||
|
||||
@override
|
||||
String? id;
|
||||
|
||||
@override
|
||||
bool? value;
|
||||
|
||||
@override
|
||||
bool mandatory;
|
||||
|
||||
@override
|
||||
String Function(bool? value)? checkPageTitle;
|
||||
|
||||
@override
|
||||
String Function(bool? value)? checkPageDescription;
|
||||
|
||||
@override
|
||||
void Function(bool? value)? onChanged;
|
||||
|
||||
@override
|
||||
void onSaved(bool? value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@override
|
||||
String? onValidate(
|
||||
bool? value, String Function(String, {List<String>? params}) translator) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class SwitchFormField extends FormField<bool> {
|
||||
SwitchFormField({
|
||||
Key? key,
|
||||
required FormFieldSetter<bool> onSaved,
|
||||
required FormFieldValidator<bool> validator,
|
||||
bool initialValue = false,
|
||||
bool autovalidate = false,
|
||||
}) : super(
|
||||
key: key,
|
||||
onSaved: onSaved,
|
||||
validator: validator,
|
||||
initialValue: initialValue,
|
||||
builder: (FormFieldState<bool> state) {
|
||||
return SwitchWidget(
|
||||
initialValue: initialValue,
|
||||
state: state,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
class SwitchWidget extends StatefulWidget {
|
||||
const SwitchWidget({
|
||||
this.initialValue = false,
|
||||
required this.state,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final bool initialValue;
|
||||
final FormFieldState<bool> state;
|
||||
|
||||
@override
|
||||
State<SwitchWidget> createState() => _SwitchWidgetState();
|
||||
}
|
||||
|
||||
class _SwitchWidgetState extends State<SwitchWidget> {
|
||||
late bool value = widget.initialValue;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Switch(
|
||||
value: value,
|
||||
onChanged: (bool value) {
|
||||
widget.state.didChange(value);
|
||||
|
||||
setState(() {
|
||||
this.value = value;
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
|
@ -4,4 +4,5 @@ export 'input_number_picker/input_number_picker.dart';
|
|||
export 'input_password/input_password.dart';
|
||||
export 'input_plain_text.dart';
|
||||
export 'input_slider/input_slider.dart';
|
||||
export 'input_switch/input_switch.dart';
|
||||
export 'input_date_picker/input_date_picker.dart';
|
||||
|
|
|
@ -17,8 +17,6 @@ dependencies:
|
|||
flutter_riverpod: ^1.0.4
|
||||
intl: ^0.17.0
|
||||
localization: ^2.1.0
|
||||
sliding_up_panel: ^2.0.0+1
|
||||
uuid: ^3.0.6
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
Loading…
Reference in a new issue