Skip to content

Commit 409df57

Browse files
fix: equality check for iteratable data types
1 parent d0f07cb commit 409df57

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

lib/src/form_builder_field.dart

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:flutter/foundation.dart';
12
import 'package:flutter/widgets.dart';
23
import 'package:flutter_form_builder/flutter_form_builder.dart';
34

@@ -185,7 +186,7 @@ class FormBuilderFieldState<F extends FormBuilderField<T>, T>
185186

186187
void _informFormForFieldChange() {
187188
if (_formBuilderState != null) {
188-
_dirty = value != initialValue;
189+
_dirty = !_hasSameValue(value, initialValue);
189190
if (enabled || readOnly) {
190191
_formBuilderState!.setInternalFieldValue<T>(widget.name, value);
191192
return;
@@ -194,6 +195,19 @@ class FormBuilderFieldState<F extends FormBuilderField<T>, T>
194195
}
195196
}
196197

198+
bool _hasSameValue(T? currentValue, T? initialValue) {
199+
if (currentValue is List && initialValue is List) {
200+
return listEquals(currentValue, initialValue);
201+
}
202+
if (currentValue is Set && initialValue is Set) {
203+
return setEquals(currentValue, initialValue);
204+
}
205+
if (currentValue is Map && initialValue is Map) {
206+
return mapEquals(currentValue, initialValue);
207+
}
208+
return currentValue == initialValue;
209+
}
210+
197211
void _touchedHandler() {
198212
if (effectiveFocusNode.hasFocus && _touched == false) {
199213
setState(() => _touched = true);

0 commit comments

Comments
 (0)