1+ import 'package:flutter/foundation.dart' ;
12import 'package:flutter/widgets.dart' ;
23import '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