From c516ce8f22dfd8c655e3a2d6826b9cd9603ddc31 Mon Sep 17 00:00:00 2001 From: Jorian van der Kolk Date: Fri, 28 Oct 2022 14:12:40 +0200 Subject: [PATCH] only validate edited field --- lib/src/widgets/item_builder/item_builder.dart | 10 +++++----- lib/src/widgets/item_builder/item_list.dart | 2 -- lib/src/widgets/profile/profile_wrapper.dart | 4 ---- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/src/widgets/item_builder/item_builder.dart b/lib/src/widgets/item_builder/item_builder.dart index 0625a0c..de86bfe 100644 --- a/lib/src/widgets/item_builder/item_builder.dart +++ b/lib/src/widgets/item_builder/item_builder.dart @@ -11,8 +11,8 @@ class ItemBuilder { final ItemBuilderOptions options; - Widget build(String key, GlobalKey formKey, dynamic value, - Widget? widget, Function(String) updateItem) { + Widget build( + String key, dynamic value, Widget? widget, Function(String) updateItem) { if (widget == null) { var controller = TextEditingController( text: '${value ?? ''}', @@ -22,14 +22,14 @@ class ItemBuilder { inputDecoration = options.inputDecorationField?[key] ?? options.inputDecoration; - + var formFieldKey = GlobalKey(); return TextFormField( - key: Key(key), + key: formFieldKey, controller: controller, decoration: inputDecoration, readOnly: options.readOnly, onFieldSubmitted: (value) { - if (formKey.currentState!.validate()) { + if (formFieldKey.currentState!.validate()) { updateItem(value); } }, diff --git a/lib/src/widgets/item_builder/item_list.dart b/lib/src/widgets/item_builder/item_list.dart index 6cdd2d2..cba9d5b 100644 --- a/lib/src/widgets/item_builder/item_list.dart +++ b/lib/src/widgets/item_builder/item_list.dart @@ -38,7 +38,6 @@ class _ItemListState extends State { ? widgets.add( builder.build( item.key, - widget.formKey, item.value, widget.typeMap[item.key], (value) { @@ -49,7 +48,6 @@ class _ItemListState extends State { : widgets.add( widget.itemBuilder!.build( item.key, - widget.formKey, item.value, widget.typeMap[item.key], (value) { diff --git a/lib/src/widgets/profile/profile_wrapper.dart b/lib/src/widgets/profile/profile_wrapper.dart index 5adad1c..6a822a6 100644 --- a/lib/src/widgets/profile/profile_wrapper.dart +++ b/lib/src/widgets/profile/profile_wrapper.dart @@ -59,7 +59,6 @@ class _ProfileWrapperState extends State { defaultItems.add( builder.build( 'first_name', - formKey, widget.user.firstName, null, (v) { @@ -77,7 +76,6 @@ class _ProfileWrapperState extends State { defaultItems.add( builder.build( 'last_name', - formKey, widget.user.lastName, null, (v) { @@ -96,7 +94,6 @@ class _ProfileWrapperState extends State { defaultItems.add( widget.itemBuilder!.build( 'first_name', - formKey, widget.user.firstName, null, (v) { @@ -114,7 +111,6 @@ class _ProfileWrapperState extends State { defaultItems.add( widget.itemBuilder!.build( 'last_name', - formKey, widget.user.lastName, null, (v) {