Merge pull request #47 from Iconica-Development/refactor/replace-ShellTranslationService

refactor: replace shelltranslationservice with validationMessage input
This commit is contained in:
Freek van de Ven 2024-02-29 16:52:11 +01:00 committed by GitHub
commit 48534c0db1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 131 additions and 113 deletions

View file

@ -128,4 +128,9 @@
## 6.3.0 - February 21th 2024 ## 6.3.0 - February 21th 2024
- Updated the `flutter_input_library` from 3.1.0 to 3.2.1 - Updated the `flutter_input_library` from 3.1.0 to 3.2.1
- Added `FlutterFormInputPhone` for phone number with dial code selection. - Added `FlutterFormInputPhone` for phone number with dial code selection.
- Added `InputDecoration` parameter to the following inputfields: `FlutterFormInputEmail` and `FlutterFormInputPassword` - Added `InputDecoration` parameter to the following inputfields: `FlutterFormInputEmail` and `FlutterFormInputPassword`
## 6.3.1 - February 29th 2024
- Removed `TranslationService` and add `validationMessage` property to fields with validation.
- Added a way to override a input field validator.
- Exposed all properties for `FlutterFormInputDateTime` provided by `flutter_input_library`.

View file

@ -35,6 +35,7 @@ class _AgePageState extends State<AgePage> {
minValue: 12, minValue: 12,
maxValue: 120, maxValue: 120,
controller: widget.inputController, controller: widget.inputController,
validationMessage: 'Please fill in your age.',
), ),
], ],
); );

View file

@ -34,7 +34,10 @@ class _CarouselPageState extends State<CarouselPage> {
amountOfPages: 4, amountOfPages: 4,
flutterFormWidgets: [ flutterFormWidgets: [
FlutterFormInputCarousel( FlutterFormInputCarousel(
controller: widget.inputController, items: getCars()) controller: widget.inputController,
items: getCars(),
validationMessage: 'Validation error message.',
)
], ],
); );
} }

View file

@ -46,6 +46,7 @@ class _DatePageState extends State<DatePage> {
), ),
label: const Text("Custom date label"), label: const Text("Custom date label"),
controller: widget.dateController, controller: widget.dateController,
validationMessage: 'Please fill in a date.',
), ),
), ),
], ],

View file

@ -40,6 +40,7 @@ class _NamePageState extends State<NamePage> {
child: FlutterFormInputPlainText( child: FlutterFormInputPlainText(
label: const Text("First Name"), label: const Text("First Name"),
controller: widget.firstNameController, controller: widget.firstNameController,
validationMessage: 'Please fill in your first name.',
), ),
), ),
if (widget.showLastName) if (widget.showLastName)
@ -48,6 +49,7 @@ class _NamePageState extends State<NamePage> {
child: FlutterFormInputPlainText( child: FlutterFormInputPlainText(
label: const Text("Last Name"), label: const Text("Last Name"),
controller: widget.lastNameController, controller: widget.lastNameController,
validationMessage: 'Please fill in your last name.',
), ),
), ),
], ],

View file

@ -189,6 +189,7 @@ class _FormExampleState extends ConsumerState<FormExample> {
child: Center( child: Center(
child: FlutterFormInputPhone( child: FlutterFormInputPhone(
controller: phoneInputController, controller: phoneInputController,
validationMessage: 'Please fill in a valid phone number',
), ),
), ),
), ),

View file

@ -9,4 +9,3 @@ export 'src/form.dart';
export 'src/widgets/input/abstractions.dart'; export 'src/widgets/input/abstractions.dart';
export 'src/widgets/input/input_types/input_types.dart'; export 'src/widgets/input/input_types/input_types.dart';
export 'utils/form.dart'; export 'utils/form.dart';
export 'utils/translation_service.dart';

View file

@ -122,6 +122,6 @@ abstract class FlutterFormInputController<T> {
/// [onValidate] is used to validate the given input by the user. /// [onValidate] is used to validate the given input by the user.
String? onValidate( String? onValidate(
T? value, T? value,
String Function(String, {List<String>? params}) translator, String validationMessage,
); );
} }

View file

@ -16,24 +16,27 @@ import 'package:flutter_input_library/flutter_input_library.dart' as input;
class FlutterFormInputCarousel extends FlutterFormInputWidget<int> { class FlutterFormInputCarousel extends FlutterFormInputWidget<int> {
const FlutterFormInputCarousel({ const FlutterFormInputCarousel({
required super.controller, required super.controller,
required this.validationMessage,
required this.items, required this.items,
super.key, super.key,
super.label, super.label,
this.validator,
this.height = 425, this.height = 425,
}); });
final List<Widget> items; final List<Widget> items;
final double height; final double height;
final String validationMessage;
final String? Function(int?)? validator;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var translator = getTranslator(context);
super.registerController(context); super.registerController(context);
return input.FlutterFormInputCarousel( return input.FlutterFormInputCarousel(
onSaved: controller.onSaved, onSaved: controller.onSaved,
validator: (value) => controller.onValidate(value, translator), validator: validator ??
(value) => controller.onValidate(value, validationMessage),
onChanged: controller.onChanged, onChanged: controller.onChanged,
initialValue: controller.value ?? 0, initialValue: controller.value ?? 0,
items: items, items: items,
@ -86,7 +89,7 @@ class FlutterFormInputCarouselController
@override @override
String? onValidate( String? onValidate(
int? value, int? value,
String Function(String, {List<String>? params}) translator, String validationMessage,
) { ) {
if (mandatory) {} if (mandatory) {}

View file

@ -33,36 +33,57 @@ class FlutterFormInputDateTime extends FlutterFormInputWidget<String> {
required super.controller, required super.controller,
required this.inputType, required this.inputType,
required this.dateFormat, required this.dateFormat,
required this.validationMessage,
this.decoration,
this.style,
super.key, super.key,
super.label, this.label,
this.showIcon = true, this.showIcon = true,
this.firstDate, this.firstDate,
this.lastDate, this.lastDate,
this.initialDate, this.initialDate,
this.initialDateTimeRange, this.initialDateTimeRange,
this.initialTime,
this.icon = Icons.calendar_today, this.icon = Icons.calendar_today,
this.initialValue,
this.onChanged,
this.onSaved,
this.validator,
this.autovalidateMode = AutovalidateMode.disabled,
this.timePickerEntryMode = TimePickerEntryMode.dial,
this.enabled = true, this.enabled = true,
this.onTapEnabled = true, this.onTapEnabled = true,
}); });
final TextStyle? style;
final InputDecoration? decoration;
final Widget? label;
final bool showIcon; final bool showIcon;
final input.FlutterFormDateTimeType inputType; final input.FlutterFormDateTimeType inputType;
final DateFormat dateFormat; final DateFormat dateFormat;
final DateTime? initialDate; final DateTime? initialDate;
final DateTimeRange? initialDateTimeRange; final DateTimeRange? initialDateTimeRange;
final TimeOfDay? initialTime;
final DateTime? firstDate; final DateTime? firstDate;
final DateTime? lastDate; final DateTime? lastDate;
final IconData icon; final IconData icon;
final String? initialValue;
final String? Function(String?)? validator;
final String validationMessage;
final void Function(String?)? onSaved;
final void Function(String?)? onChanged;
final AutovalidateMode autovalidateMode;
final TimePickerEntryMode timePickerEntryMode;
final bool enabled; final bool enabled;
final bool onTapEnabled; final bool onTapEnabled;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var translator = getTranslator(context);
super.registerController(context); super.registerController(context);
return input.FlutterFormInputDateTime( return input.FlutterFormInputDateTime(
enabled: enabled, enabled: enabled,
showIcon: showIcon, showIcon: showIcon,
decoration: decoration,
onTapEnabled: onTapEnabled, onTapEnabled: onTapEnabled,
label: label, label: label,
icon: icon, icon: icon,
@ -71,7 +92,8 @@ class FlutterFormInputDateTime extends FlutterFormInputWidget<String> {
inputType: inputType, inputType: inputType,
onChanged: (value) => controller.onChanged?.call(value), onChanged: (value) => controller.onChanged?.call(value),
onSaved: controller.onSaved, onSaved: controller.onSaved,
validator: (value) => controller.onValidate(value, translator), validator: validator ??
(value) => controller.onValidate(value, validationMessage),
initialValue: controller.value, initialValue: controller.value,
dateFormat: dateFormat, dateFormat: dateFormat,
initialDate: initialDate, initialDate: initialDate,
@ -143,11 +165,11 @@ class FlutterFormInputDateTimeController
@override @override
String? onValidate( String? onValidate(
String? value, String? value,
String Function(String, {List<String>? params}) translator, String validationMessage,
) { ) {
if (mandatory) { if (mandatory) {
if (value == null || value.isEmpty) { if (value == null || value.isEmpty) {
return translator('shell.form.error.empty'); return validationMessage;
} }
} }

View file

@ -16,21 +16,23 @@ class FlutterFormInputEmail extends FlutterFormInputWidget<String> {
/// The [key], [focusNode], [label], and [enabled] parameters are optional. /// The [key], [focusNode], [label], and [enabled] parameters are optional.
const FlutterFormInputEmail({ const FlutterFormInputEmail({
required super.controller, required super.controller,
required this.validationMessage,
super.key, super.key,
super.focusNode, super.focusNode,
super.label, super.label,
bool? enabled, bool? enabled,
this.validator,
this.decoration, this.decoration,
}) : super( }) : super(
enabled: enabled ?? true, enabled: enabled ?? true,
); );
final InputDecoration? decoration; final InputDecoration? decoration;
final String validationMessage;
final String? Function(String?)? validator;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var translator = getTranslator(context);
super.registerController(context); super.registerController(context);
return input.FlutterFormInputPlainText( return input.FlutterFormInputPlainText(
@ -40,7 +42,8 @@ class FlutterFormInputEmail extends FlutterFormInputWidget<String> {
controller.onSaved(value); controller.onSaved(value);
}, },
focusNode: focusNode, focusNode: focusNode,
validator: (value) => controller.onValidate(value, translator), validator: validator ??
(value) => controller.onValidate(value, validationMessage),
onChanged: (value) => controller.onChanged?.call(value), onChanged: (value) => controller.onChanged?.call(value),
decoration: decoration, decoration: decoration,
); );
@ -98,17 +101,17 @@ class FlutterFormInputEmailController
@override @override
String? onValidate( String? onValidate(
String? value, String? value,
String Function(String, {List<String>? params}) translator, String validationMessage,
) { ) {
if (mandatory) { if (mandatory) {
if (value == null || value.isEmpty) { if (value == null || value.isEmpty) {
return translator('shell.form.error.empty'); return validationMessage;
} }
if (!RegExp( if (!RegExp(
r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+", r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+",
).hasMatch(value)) { ).hasMatch(value)) {
return translator('shell.form.error.email.notValid'); return validationMessage;
} }
} }

View file

@ -15,26 +15,29 @@ import 'package:flutter_input_library/flutter_input_library.dart' as input;
class FlutterFormInputNumberPicker extends FlutterFormInputWidget<int> { class FlutterFormInputNumberPicker extends FlutterFormInputWidget<int> {
const FlutterFormInputNumberPicker({ const FlutterFormInputNumberPicker({
required super.controller, required super.controller,
required this.validationMessage,
super.key, super.key,
super.label, super.label,
this.validator,
this.minValue = 0, this.minValue = 0,
this.maxValue = 100, this.maxValue = 100,
}) : assert(minValue < maxValue, 'minValue must be less than maxValue'); }) : assert(minValue < maxValue, 'minValue must be less than maxValue');
final int minValue; final int minValue;
final int maxValue; final int maxValue;
final String validationMessage;
final String? Function(int?)? validator;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var translator = getTranslator(context);
super.registerController(context); super.registerController(context);
return input.FlutterFormInputNumberPicker( return input.FlutterFormInputNumberPicker(
minValue: minValue, minValue: minValue,
maxValue: maxValue, maxValue: maxValue,
onSaved: controller.onSaved, onSaved: controller.onSaved,
validator: (value) => controller.onValidate(value, translator), validator: validator ??
(value) => controller.onValidate(value, validationMessage),
onChanged: (value) => controller.onChanged?.call(value), onChanged: (value) => controller.onChanged?.call(value),
initialValue: controller.value ?? minValue, initialValue: controller.value ?? minValue,
); );
@ -91,7 +94,7 @@ class FlutterFormInputNumberPickerController
@override @override
String? onValidate( String? onValidate(
int? value, int? value,
String Function(String, {List<String>? params}) translator, String validationMessage,
) { ) {
if (mandatory) {} if (mandatory) {}

View file

@ -12,29 +12,31 @@ import 'package:flutter_input_library/flutter_input_library.dart' as input;
class FlutterFormInputPassword extends FlutterFormInputWidget<String> { class FlutterFormInputPassword extends FlutterFormInputWidget<String> {
const FlutterFormInputPassword({ const FlutterFormInputPassword({
required super.controller, required super.controller,
required this.validationMessage,
super.key, super.key,
super.focusNode, super.focusNode,
super.label, super.label,
bool? enabled, bool? enabled,
this.validator,
this.decoration, this.decoration,
}) : super( }) : super(
enabled: enabled ?? true, enabled: enabled ?? true,
); );
final InputDecoration? decoration; final InputDecoration? decoration;
final String validationMessage;
final String? Function(String?)? validator;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
super.registerController(context); super.registerController(context);
var translator = getTranslator(context);
return input.FlutterFormInputPassword( return input.FlutterFormInputPassword(
enabled: enabled, enabled: enabled,
initialValue: controller.value, initialValue: controller.value,
focusNode: focusNode, focusNode: focusNode,
onSaved: controller.onSaved, onSaved: controller.onSaved,
validator: (value) => controller.onValidate(value, translator), validator: validator ??
(value) => controller.onValidate(value, validationMessage),
onChanged: (value) => controller.onChanged?.call(value), onChanged: (value) => controller.onChanged?.call(value),
onFieldSubmitted: (value) => controller.onSubmit?.call(value), onFieldSubmitted: (value) => controller.onSubmit?.call(value),
decoration: decoration, decoration: decoration,
@ -93,15 +95,15 @@ class FlutterFormInputPasswordController
@override @override
String? onValidate( String? onValidate(
String? value, String? value,
String Function(String, {List<String>? params}) translator, String validationMessage,
) { ) {
if (mandatory) { if (mandatory) {
if (value == null || value.isEmpty) { if (value == null || value.isEmpty) {
return translator('Field can not be empty'); return validationMessage;
} }
if (value.length < 6) { if (value.length < 6) {
return translator('Field should be at least 6 characters long'); return validationMessage;
} }
} }

View file

@ -14,12 +14,14 @@ import 'package:flutter_input_library/flutter_input_library.dart' as input;
class FlutterFormInputPhone extends FlutterFormInputWidget<input.PhoneNumber?> { class FlutterFormInputPhone extends FlutterFormInputWidget<input.PhoneNumber?> {
const FlutterFormInputPhone({ const FlutterFormInputPhone({
required super.controller, required super.controller,
required this.validationMessage,
super.key, super.key,
super.focusNode, super.focusNode,
super.label, super.label,
this.decoration, this.decoration,
this.enabled = true, this.enabled = true,
this.numberFieldStyle, this.numberFieldStyle,
this.validator,
this.dialCodeSelectorStyle, this.dialCodeSelectorStyle,
this.dialCodeSelectorPadding = const EdgeInsets.only(top: 6), this.dialCodeSelectorPadding = const EdgeInsets.only(top: 6),
this.textAlignVertical = TextAlignVertical.top, this.textAlignVertical = TextAlignVertical.top,
@ -32,11 +34,11 @@ class FlutterFormInputPhone extends FlutterFormInputWidget<input.PhoneNumber?> {
final TextStyle? dialCodeSelectorStyle; final TextStyle? dialCodeSelectorStyle;
final EdgeInsets dialCodeSelectorPadding; final EdgeInsets dialCodeSelectorPadding;
final TextAlignVertical textAlignVertical; final TextAlignVertical textAlignVertical;
final String validationMessage;
final String? Function(PhoneNumber?)? validator;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var translator = getTranslator(context);
super.registerController(context); super.registerController(context);
var inputDecoration = decoration ?? var inputDecoration = decoration ??
@ -50,7 +52,8 @@ class FlutterFormInputPhone extends FlutterFormInputWidget<input.PhoneNumber?> {
enabled: enabled, enabled: enabled,
initialValue: controller.value, initialValue: controller.value,
onSaved: controller.onSaved, onSaved: controller.onSaved,
validator: (value) => controller.onValidate(value, translator), validator: validator ??
(value) => controller.onValidate(value, validationMessage),
onChanged: (value) => controller.onChanged?.call(value), onChanged: (value) => controller.onChanged?.call(value),
onFieldSubmitted: (value) => controller.onSubmit?.call(value), onFieldSubmitted: (value) => controller.onSubmit?.call(value),
decoration: inputDecoration, decoration: inputDecoration,
@ -100,11 +103,11 @@ class FlutterFormInputPhoneController
@override @override
String? onValidate( String? onValidate(
input.PhoneNumber? value, input.PhoneNumber? value,
String Function(String, {List<String>? params}) translator, String validationMessage,
) { ) {
if (mandatory) { if (mandatory) {
if (value == null || value.number == null) { if (value == null || value.number == null) {
return translator('Field can not be empty'); return validationMessage;
} }
} }

View file

@ -20,6 +20,7 @@ class FlutterFormInputPlainText extends FlutterFormInputWidget<String> {
/// [enabled], [style], and [textCapitalization] parameters are optional. /// [enabled], [style], and [textCapitalization] parameters are optional.
const FlutterFormInputPlainText({ const FlutterFormInputPlainText({
required super.controller, required super.controller,
required this.validationMessage,
super.key, super.key,
super.focusNode, super.focusNode,
super.label, super.label,
@ -30,6 +31,7 @@ class FlutterFormInputPlainText extends FlutterFormInputWidget<String> {
this.scrollPadding, this.scrollPadding,
this.maxLength, this.maxLength,
this.keyboardType, this.keyboardType,
this.validator,
this.enabled = true, this.enabled = true,
this.style, this.style,
this.textCapitalization = TextCapitalization.none, this.textCapitalization = TextCapitalization.none,
@ -46,11 +48,11 @@ class FlutterFormInputPlainText extends FlutterFormInputWidget<String> {
final bool enabled; final bool enabled;
final TextStyle? style; final TextStyle? style;
final TextCapitalization textCapitalization; final TextCapitalization textCapitalization;
final String validationMessage;
final String? Function(String?)? validator;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var translator = getTranslator(context);
super.registerController(context); super.registerController(context);
var inputDecoration = decoration ?? var inputDecoration = decoration ??
@ -65,7 +67,8 @@ class FlutterFormInputPlainText extends FlutterFormInputWidget<String> {
initialValue: controller.value, initialValue: controller.value,
focusNode: focusNode, focusNode: focusNode,
onSaved: controller.onSaved, onSaved: controller.onSaved,
validator: (value) => controller.onValidate(value, translator), validator: validator ??
(value) => controller.onValidate(value, validationMessage),
onChanged: (value) => controller.onChanged?.call(value), onChanged: (value) => controller.onChanged?.call(value),
onFieldSubmitted: (value) => controller.onSubmit?.call(value), onFieldSubmitted: (value) => controller.onSubmit?.call(value),
decoration: inputDecoration, decoration: inputDecoration,
@ -89,10 +92,12 @@ class FlutterFormInputPlainText extends FlutterFormInputWidget<String> {
class FlutterFormInputMultiLine extends StatelessWidget { class FlutterFormInputMultiLine extends StatelessWidget {
const FlutterFormInputMultiLine({ const FlutterFormInputMultiLine({
required this.controller, required this.controller,
required this.validationMessage,
super.key, super.key,
this.focusNode, this.focusNode,
this.label, this.label,
this.hint, this.hint,
this.validator,
this.maxCharacters, this.maxCharacters,
this.enabled = true, this.enabled = true,
this.textCapitalization = TextCapitalization.sentences, this.textCapitalization = TextCapitalization.sentences,
@ -119,23 +124,24 @@ class FlutterFormInputMultiLine extends StatelessWidget {
/// The capitalization behavior for the input field. /// The capitalization behavior for the input field.
final TextCapitalization textCapitalization; final TextCapitalization textCapitalization;
@override final String validationMessage;
Widget build(BuildContext context) {
var translator = getTranslator(context);
return input.FlutterFormInputMultiLine( final String? Function(String?)? validator;
enabled: enabled,
label: label, @override
hint: hint, Widget build(BuildContext context) => input.FlutterFormInputMultiLine(
focusNode: focusNode, enabled: enabled,
initialValue: controller.value, label: label,
maxCharacters: maxCharacters, hint: hint,
onChanged: controller.onChanged, focusNode: focusNode,
onSaved: controller.onSaved, initialValue: controller.value,
validator: (v) => controller.onValidate(v, translator), maxCharacters: maxCharacters,
textCapitalization: textCapitalization, onChanged: controller.onChanged,
); onSaved: controller.onSaved,
} validator: validator ??
(value) => controller.onValidate(value, validationMessage),
textCapitalization: textCapitalization,
);
} }
/// Controller for plain text used by a [FlutterFormInputWidget] used in a /// Controller for plain text used by a [FlutterFormInputWidget] used in a
@ -189,11 +195,11 @@ class FlutterFormInputPlainTextController
@override @override
String? onValidate( String? onValidate(
String? value, String? value,
String Function(String, {List<String>? params}) translator, String validationMessage,
) { ) {
if (mandatory) { if (mandatory) {
if (value == null || value.isEmpty) { if (value == null || value.isEmpty) {
return translator('Field can not be empty'); return validationMessage;
} }
} }

View file

@ -19,26 +19,29 @@ class FlutterFormInputSlider extends FlutterFormInputWidget<double> {
/// The [enabled] parameter specifies whether the input field is enabled. /// The [enabled] parameter specifies whether the input field is enabled.
const FlutterFormInputSlider({ const FlutterFormInputSlider({
required super.controller, required super.controller,
required this.validationMessage,
super.key, super.key,
super.focusNode, super.focusNode,
super.label, super.label,
this.validator,
this.minValue = 0, this.minValue = 0,
this.maxValue = 100, this.maxValue = 100,
}) : assert(minValue < maxValue, 'minValue must be less than maxValue'); }) : assert(minValue < maxValue, 'minValue must be less than maxValue');
final int minValue; final int minValue;
final int maxValue; final int maxValue;
final String validationMessage;
final String? Function(double?)? validator;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var translator = getTranslator(context);
super.registerController(context); super.registerController(context);
return input.FlutterFormInputSlider( return input.FlutterFormInputSlider(
focusNode: focusNode, focusNode: focusNode,
onSaved: controller.onSaved, onSaved: controller.onSaved,
validator: (value) => controller.onValidate(value, translator), validator: validator ??
(value) => controller.onValidate(value, validationMessage),
); );
} }
} }
@ -93,7 +96,7 @@ class FlutterFormInputSliderController
@override @override
String? onValidate( String? onValidate(
double? value, double? value,
String Function(String, {List<String>? params}) translator, String validationMessage,
) { ) {
if (mandatory) {} if (mandatory) {}

View file

@ -14,22 +14,26 @@ import 'package:flutter_input_library/flutter_input_library.dart' as input;
class FlutterFormInputSwitch extends FlutterFormInputWidget<bool> { class FlutterFormInputSwitch extends FlutterFormInputWidget<bool> {
const FlutterFormInputSwitch({ const FlutterFormInputSwitch({
required super.controller, required super.controller,
required this.validationMessage,
super.key, super.key,
super.focusNode, super.focusNode,
super.label, super.label,
this.validator,
}); });
final String validationMessage;
final String? Function(bool?)? validator;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var translator = getTranslator(context);
super.registerController(context); super.registerController(context);
return input.FlutterFormInputBool( return input.FlutterFormInputBool(
focusNode: focusNode, focusNode: focusNode,
onSaved: controller.onSaved, onSaved: controller.onSaved,
onChanged: controller.onChanged, onChanged: controller.onChanged,
validator: (value) => controller.onValidate(value, translator), validator: validator ??
(value) => controller.onValidate(value, validationMessage),
initialValue: controller.value ?? false, initialValue: controller.value ?? false,
widgetType: input.BoolWidgetType.switchWidget, widgetType: input.BoolWidgetType.switchWidget,
); );
@ -86,7 +90,7 @@ class FlutterFormInputSwitchController
@override @override
String? onValidate( String? onValidate(
bool? value, bool? value,
String Function(String, {List<String>? params}) translator, String validationMessage,
) => ) =>
null; null;
} }

View file

@ -1,48 +0,0 @@
// SPDX-FileCopyrightText: 2022 Iconica
//
// SPDX-License-Identifier: BSD-3-Clause
import 'package:flutter/material.dart';
abstract class TranslationService {
TranslationService._();
String translate(
BuildContext context,
String key, {
List<String>? params,
});
String number(double value);
}
typedef Translator = String Function(
String, {
List<String>? params,
});
class ShellTranslationService implements TranslationService {
@override
String number(double value) => value.toStringAsFixed(2);
@override
String translate(BuildContext context, String key, {List<String>? params}) =>
key;
}
Translator getTranslator(BuildContext context) {
try {
var translator = ShellTranslationService().translate;
return (
String key, {
List<String>? params,
}) =>
translator(context, key, params: params);
} on Exception catch (_) {
return (
String key, {
List<String>? params,
}) =>
key;
}
}

View file

@ -1,6 +1,6 @@
name: flutter_form_wizard name: flutter_form_wizard
description: A new Flutter package project. description: A new Flutter package project.
version: 6.3.0 version: 6.3.1
homepage: https://github.com/Iconica-Development/flutter_form_wizard homepage: https://github.com/Iconica-Development/flutter_form_wizard
publish_to: none publish_to: none

View file

@ -56,6 +56,7 @@ void main() {
child: FlutterFormInputPlainText( child: FlutterFormInputPlainText(
label: const Text('Field1Label'), label: const Text('Field1Label'),
controller: testField1Controller, controller: testField1Controller,
validationMessage: 'Please fill in this field',
), ),
), ),
), ),
@ -64,6 +65,7 @@ void main() {
child: FlutterFormInputPlainText( child: FlutterFormInputPlainText(
label: const Text('Field2Label'), label: const Text('Field2Label'),
controller: testField2Controller, controller: testField2Controller,
validationMessage: 'Please fill in this field',
), ),
), ),
), ),
@ -154,6 +156,7 @@ void main() {
child: FlutterFormInputPlainText( child: FlutterFormInputPlainText(
label: const Text('Field1Label'), label: const Text('Field1Label'),
controller: testField1Controller, controller: testField1Controller,
validationMessage: 'Please fill in this field',
), ),
), ),
), ),
@ -162,6 +165,7 @@ void main() {
child: FlutterFormInputPlainText( child: FlutterFormInputPlainText(
label: const Text('Field2Label'), label: const Text('Field2Label'),
controller: testField2Controller, controller: testField2Controller,
validationMessage: 'Please fill in this field',
), ),
), ),
), ),
@ -260,6 +264,7 @@ void main() {
child: FlutterFormInputPlainText( child: FlutterFormInputPlainText(
label: const Text('Field1Label'), label: const Text('Field1Label'),
controller: testField1Controller, controller: testField1Controller,
validationMessage: 'Field can not be empty',
), ),
), ),
), ),