Added the ability to set the enabled of textfields

This commit is contained in:
Jacques 2023-10-26 14:08:21 +02:00
parent 2f0ceff64e
commit cfc051531a
3 changed files with 42 additions and 26 deletions

View file

@ -29,6 +29,7 @@ class DateTimeInputField extends StatefulWidget {
this.validator, this.validator,
required this.timePickerEntryMode, required this.timePickerEntryMode,
required this.style, required this.style,
this.enabled = true,
}) : super( }) : super(
key: key, key: key,
); );
@ -50,6 +51,7 @@ class DateTimeInputField extends StatefulWidget {
final void Function(String?)? onSaved; final void Function(String?)? onSaved;
final void Function(String?)? onChanged; final void Function(String?)? onChanged;
final TimePickerEntryMode timePickerEntryMode; final TimePickerEntryMode timePickerEntryMode;
final bool enabled;
@override @override
State<DateTimeInputField> createState() => _DateInputFieldState(); State<DateTimeInputField> createState() => _DateInputFieldState();
@ -128,34 +130,38 @@ class _DateInputFieldState extends State<DateTimeInputField> {
}); });
break; break;
case FlutterFormDateTimeType.range: case FlutterFormDateTimeType.range:
userInput = (await showDateRangePicker( if (context.mounted) {
context: context, userInput = (await showDateRangePicker(
firstDate: firstDate, context: context,
lastDate: lastDate, firstDate: firstDate,
initialDateRange: initialDateRange) lastDate: lastDate,
.then((value) { initialDateRange: initialDateRange)
return value != null .then((value) {
? '${widget.dateFormat.format(value.start)} - ${widget.dateFormat.format(value.end)}' return value != null
: ''; ? '${widget.dateFormat.format(value.start)} - ${widget.dateFormat.format(value.end)}'
})) : '';
.toString(); }))
.toString();
}
break; break;
case FlutterFormDateTimeType.time: case FlutterFormDateTimeType.time:
userInput = await showTimePicker( if (context.mounted) {
initialEntryMode: widget.timePickerEntryMode, userInput = await showTimePicker(
builder: (BuildContext context, Widget? child) { initialEntryMode: widget.timePickerEntryMode,
return MediaQuery( builder: (BuildContext context, Widget? child) {
data: MediaQuery.of(context) return MediaQuery(
.copyWith(alwaysUse24HourFormat: true), data: MediaQuery.of(context)
child: child!, .copyWith(alwaysUse24HourFormat: true),
); child: child!,
}, );
context: context, },
initialTime: initialTimeOfDay, context: context,
).then((value) => value == null initialTime: initialTimeOfDay,
? '' ).then((value) => value == null
: MaterialLocalizations.of(context) ? ''
.formatTimeOfDay(value, alwaysUse24HourFormat: true)); : MaterialLocalizations.of(context)
.formatTimeOfDay(value, alwaysUse24HourFormat: true));
}
} }
return userInput; return userInput;
} }
@ -185,6 +191,7 @@ class _DateInputFieldState extends State<DateTimeInputField> {
focusColor: Theme.of(context).primaryColor, focusColor: Theme.of(context).primaryColor,
label: widget.label ?? const Text("Date"), label: widget.label ?? const Text("Date"),
), ),
enabled: widget.enabled,
); );
} }
} }

View file

@ -14,6 +14,7 @@ class FlutterFormInputPassword extends StatefulWidget {
final String? Function(String?)? validator; final String? Function(String?)? validator;
final Function(String?)? onChanged; final Function(String?)? onChanged;
final Function(String?)? onFieldSubmitted; final Function(String?)? onFieldSubmitted;
final bool enabled;
const FlutterFormInputPassword({ const FlutterFormInputPassword({
Key? key, Key? key,
@ -24,6 +25,7 @@ class FlutterFormInputPassword extends StatefulWidget {
this.validator, this.validator,
this.onChanged, this.onChanged,
this.onFieldSubmitted, this.onFieldSubmitted,
this.enabled = true,
}) : super(key: key); }) : super(key: key);
@override @override
@ -54,6 +56,7 @@ class _PasswordTextFieldState extends State<FlutterFormInputPassword> {
icon: Icon(obscured ? Icons.visibility_off : Icons.visibility), icon: Icon(obscured ? Icons.visibility_off : Icons.visibility),
), ),
), ),
enabled: widget.enabled,
); );
} }
} }

View file

@ -22,6 +22,7 @@ class FlutterFormInputPlainText extends StatelessWidget {
this.validator, this.validator,
this.onFieldSubmitted, this.onFieldSubmitted,
this.style, this.style,
this.enabled = true,
}) : super( }) : super(
key: key, key: key,
); );
@ -41,6 +42,7 @@ class FlutterFormInputPlainText extends StatelessWidget {
final Function(String?)? onChanged; final Function(String?)? onChanged;
final Function(String?)? onFieldSubmitted; final Function(String?)? onFieldSubmitted;
final TextStyle? style; final TextStyle? style;
final bool enabled;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -64,6 +66,7 @@ class FlutterFormInputPlainText extends StatelessWidget {
maxLines: maxLines, maxLines: maxLines,
maxLength: maxLength, maxLength: maxLength,
keyboardType: keyboardType, keyboardType: keyboardType,
enabled: enabled,
); );
} }
} }
@ -75,6 +78,7 @@ class FlutterFormInputMultiLine extends StatelessWidget {
this.focusNode, this.focusNode,
this.hint, this.hint,
this.maxCharacters, this.maxCharacters,
this.enabled = true,
this.scrollPadding, this.scrollPadding,
this.keyboardType, this.keyboardType,
this.initialValue, this.initialValue,
@ -89,6 +93,7 @@ class FlutterFormInputMultiLine extends StatelessWidget {
final FocusNode? focusNode; final FocusNode? focusNode;
final String? hint; final String? hint;
final int? maxCharacters; final int? maxCharacters;
final bool enabled;
final InputDecoration? decoration; final InputDecoration? decoration;
final EdgeInsets? scrollPadding; final EdgeInsets? scrollPadding;
@ -131,6 +136,7 @@ class FlutterFormInputMultiLine extends StatelessWidget {
), ),
filled: true, filled: true,
), ),
enabled: enabled,
), ),
), ),
], ],