From a911006b835a8ebe7207ab4fb43990b96f62b174 Mon Sep 17 00:00:00 2001 From: ottodaempfle Date: Thu, 11 Jun 2026 12:49:05 +0200 Subject: [PATCH 1/3] removed on next frame --- lib/src/text_field/base_text_field.dart | 42 ++++++++++++++----------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/lib/src/text_field/base_text_field.dart b/lib/src/text_field/base_text_field.dart index 9a96342..90d216d 100644 --- a/lib/src/text_field/base_text_field.dart +++ b/lib/src/text_field/base_text_field.dart @@ -256,25 +256,29 @@ class BaseTextFieldState extends State // We don't need anything whenever the change is from the textfield itself if (_textEditingController.text == text) return; - // this will be called, whenever a change comes from outside and we need to handle the changed event - onNextFrame(() { - if (text.isEmpty) { - _textEditingController.clear(); - } else { - final selection = _textEditingController.selection; - - final isNewTextSmaller = oldWidget.text.length > text.length; - _textEditingController.value = _textEditingController.value.copyWith( - text: text, - selection: isNewTextSmaller - ? TextSelection.collapsed(offset: text.length) - : selection.copyWith( - baseOffset: text.length, - extentOffset: text.length, - ), - ); - } - }); + // The change comes from outside. We update [_previousTextValue] before + // mutating the controller so the controller listener ([_onChanged]) + // short-circuits and does not re-emit [onChanged] for a value we already + // know about (which would write the external value straight back). + _previousTextValue = text; + + // this will be called, whenever a change comes from outside and we need to handle the changed event. + if (text.isEmpty) { + _textEditingController.clear(); + } else { + final selection = _textEditingController.selection; + + final isNewTextSmaller = oldWidget.text.length > text.length; + _textEditingController.value = _textEditingController.value.copyWith( + text: text, + selection: isNewTextSmaller + ? TextSelection.collapsed(offset: text.length) + : selection.copyWith( + baseOffset: text.length, + extentOffset: text.length, + ), + ); + } } } From 9c31f9b9d565a82d1a4ad0b77b8184a44673fdc2 Mon Sep 17 00:00:00 2001 From: ottodaempfle Date: Thu, 11 Jun 2026 13:11:56 +0200 Subject: [PATCH 2/3] updated base text field --- lib/src/text_field/base_text_field.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/text_field/base_text_field.dart b/lib/src/text_field/base_text_field.dart index 90d216d..6c011b1 100644 --- a/lib/src/text_field/base_text_field.dart +++ b/lib/src/text_field/base_text_field.dart @@ -258,7 +258,7 @@ class BaseTextFieldState extends State // The change comes from outside. We update [_previousTextValue] before // mutating the controller so the controller listener ([_onChanged]) - // short-circuits and does not re-emit [onChanged] for a value we already + // does not re-emit [onChanged] for a value we already // know about (which would write the external value straight back). _previousTextValue = text; From 088a0e723a74efbf49fac4a92b8717f8fd456cad Mon Sep 17 00:00:00 2001 From: ottodaempfle Date: Thu, 11 Jun 2026 13:23:24 +0200 Subject: [PATCH 3/3] added on next frame back --- lib/src/text_field/base_text_field.dart | 34 +++++++++++++------------ 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/lib/src/text_field/base_text_field.dart b/lib/src/text_field/base_text_field.dart index 6c011b1..22b2429 100644 --- a/lib/src/text_field/base_text_field.dart +++ b/lib/src/text_field/base_text_field.dart @@ -263,22 +263,24 @@ class BaseTextFieldState extends State _previousTextValue = text; // this will be called, whenever a change comes from outside and we need to handle the changed event. - if (text.isEmpty) { - _textEditingController.clear(); - } else { - final selection = _textEditingController.selection; - - final isNewTextSmaller = oldWidget.text.length > text.length; - _textEditingController.value = _textEditingController.value.copyWith( - text: text, - selection: isNewTextSmaller - ? TextSelection.collapsed(offset: text.length) - : selection.copyWith( - baseOffset: text.length, - extentOffset: text.length, - ), - ); - } + onNextFrame(() { + if (text.isEmpty) { + _textEditingController.clear(); + } else { + final selection = _textEditingController.selection; + + final isNewTextSmaller = oldWidget.text.length > text.length; + _textEditingController.value = _textEditingController.value.copyWith( + text: text, + selection: isNewTextSmaller + ? TextSelection.collapsed(offset: text.length) + : selection.copyWith( + baseOffset: text.length, + extentOffset: text.length, + ), + ); + } + }); } }