Skip to content

Commit 1ffa759

Browse files
Warn against the listener-loop footgun in TextEditingController.text
1 parent 06154c8 commit 1ffa759

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎packages/flutter/lib/src/widgets/editable_text.dart‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,13 @@ class TextEditingController extends ValueNotifier<TextEditingValue> {
278278
/// marked as needing to build during those phases, and throws an exception
279279
/// when a listener attempts it. Setting the text from a build method also
280280
/// risks rebuilding in a loop, as every notification can schedule another
281-
/// build that sets the text again. This property can be set from a listener
282-
/// added to this [TextEditingController].
281+
/// build that sets the text again.
282+
///
283+
/// This property can be set from a listener added to this
284+
/// [TextEditingController], but take care to avoid an infinite loop: setting
285+
/// the text notifies listeners, so a listener that sets the text will be
286+
/// triggered again. A common way to avoid this is to remove the listener
287+
/// before setting the text and re-add it afterward.
283288
set text(String newText) {
284289
value = value.copyWith(
285290
text: newText,

0 commit comments

Comments
 (0)