From 2468d2bf3539af48039989997e4426ea66af0639 Mon Sep 17 00:00:00 2001 From: Matias de Andrea Date: Sun, 22 Jan 2023 01:56:16 +0100 Subject: [PATCH] feat: Able to change dynamically field name --- lib/src/form_builder_field.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/src/form_builder_field.dart b/lib/src/form_builder_field.dart index b6955bb448..d54cc0b38a 100644 --- a/lib/src/form_builder_field.dart +++ b/lib/src/form_builder_field.dart @@ -133,6 +133,10 @@ class FormBuilderFieldState, T> @override void didUpdateWidget(covariant FormBuilderField oldWidget) { super.didUpdateWidget(oldWidget); + if (widget.name != oldWidget.name) { + _formBuilderState?.unregisterField(oldWidget.name, this); + _formBuilderState?.registerField(widget.name, this); + } if (widget.focusNode != oldWidget.focusNode) { focusAttachment?.detach(); effectiveFocusNode.removeListener(_touchedHandler);