Skip to content
This repository was archived by the owner on May 20, 2023. It is now read-only.

Commit 8d3b6a9

Browse files
Googlernshahan
authored andcommitted
Prevent material_auto_suggest_input from marking itself as dirty when it receives an initial form value.
PiperOrigin-RevId: 193159935
1 parent 7db80db commit 8d3b6a9

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lib/material_input/material_auto_suggest_input.dart

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -552,10 +552,17 @@ class MaterialAutoSuggestInputComponent extends MaterialSelectBase
552552
/// Filters suggestion list according to input.
553553
@override
554554
set inputText(String inputText) {
555+
if (_setInputText(inputText) && _callback != null) {
556+
_callback(_inputText);
557+
}
558+
}
559+
560+
/// Returns true if [inputText] was changed.
561+
bool _setInputText(String inputText) {
555562
inputText ??= '';
556563

557564
if (inputText == _inputText) {
558-
return;
565+
return false;
559566
}
560567

561568
if (selection != _defaultSelection &&
@@ -564,7 +571,7 @@ class MaterialAutoSuggestInputComponent extends MaterialSelectBase
564571
// deselect previously selected item as the component was not asked to
565572
// clear the text upon selection, indicating that the selection is bound
566573
// to the text.
567-
// TODO(google): Should we clear the selection if they earse even a letter?
574+
// TODO(google): Should we clear the selection if they erase even a letter?
568575
if (inputText != itemRenderer(_lastSelectedItem)) {
569576
selection.deselect(_lastSelectedItem);
570577
_lastSelectedItem = null;
@@ -573,7 +580,7 @@ class MaterialAutoSuggestInputComponent extends MaterialSelectBase
573580
_inputText = inputText;
574581
_inputChange.add(inputText);
575582
_filterSuggestions();
576-
if (_callback != null) _callback(inputText);
583+
return true;
577584
}
578585

579586
@Output('clear')
@@ -702,7 +709,7 @@ class MaterialAutoSuggestInputComponent extends MaterialSelectBase
702709

703710
@override
704711
void writeValue(newValue) {
705-
inputText = newValue as String;
712+
_setInputText(newValue as String);
706713
}
707714

708715
@override
@@ -750,7 +757,7 @@ class MaterialAutoSuggestInputComponent extends MaterialSelectBase
750757
_isInitialized = true;
751758
scheduleMicrotask(() {
752759
if (inputText.isEmpty && _lastSelectedItem != null) {
753-
inputText = itemRenderer(_lastSelectedItem);
760+
_setInputText(itemRenderer(_lastSelectedItem));
754761
}
755762
});
756763
}

0 commit comments

Comments
 (0)