Repository navigation
Open
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: first hourThe first hour of using FlutterThe first hour of using Fluttera: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsd: api docsIssues with https://api.flutter.dev/Issues with https://api.flutter.dev/found in release: 3.3Found to occur in 3.3Found to occur in 3.3found in release: 3.6Found to occur in 3.6Found to occur in 3.6frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Description
TextEditingController.text docs say it shouldn't be updated in a build method, but it doesn't explain why, it just says the listeners will be called. Is this for performance reasons, so the listeners won't lock the build method? Or are there any other issues as well?
I think the docs should include a more explained reason on the side-effects, so devs could evaluate more the impacts of their code and their decisions, or facilitate fixing bugs.
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: first hourThe first hour of using FlutterThe first hour of using Fluttera: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsd: api docsIssues with https://api.flutter.dev/Issues with https://api.flutter.dev/found in release: 3.3Found to occur in 3.3Found to occur in 3.3found in release: 3.6Found to occur in 3.6Found to occur in 3.6frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Activity
gaaclarke commentedon Dec 10, 2019
flutter/packages/flutter/lib/src/widgets/editable_text.dart
Line 137 in 78951b0
I think setting the property instead of using the constructor parameter would look very non-idiomatic. It sounds like they did attempt to explain why someone shouldn't do it. Since you found it confusing maybe you can suggest a fix @feinstein?
feinstein commentedon Dec 11, 2019
@gaaclarke the
textproperty inTextEditingControlleris for changing thetexton the fly, like in a button. In this case, we don't want to rebuild a newTextEditingController, so the constructor parameter isn't helpful and we need a separate property for this.I can't suggest an fix as I don't know why they suggested this. For example, if the recommendation is only about performance issues, then it should say something as :
But if the reason is something else entirely, like calling internal methods of the framework that shouldn't be called inside the
buildmethod, then I don't know, and only they can explain the reason.gaaclarke commentedon Dec 11, 2019
I think there is some confusion about Reative Programming. When you change a value you rebuild the widgets that rely on that value. Check out the default flutter project that gets created when you run
flutter create foobar. The code looks like this:Notice how _counter is used in the Text widget and how it is getting set. That is the correct usage of the paradigm.
feinstein commentedon Dec 11, 2019
That's correct for a
StatelessWidgetbut withStatefulWidgetsthings aren't so simple, as your state can be defined in multiple places, callbacks, that's why the Flutter framework has several controllers, likeTextEditingController,AnimationController,PageController, as explained here.What you are implying is that the Flutter framework creators are wrong in exposing the
textproperty, and not only this property, but all the other ones from several other controllers. This controller pattern is common in Flutter in general and is very useful for streamlining reactive programming, otherwise you will have to create several variables and update them in callbacks, which gets messy very quickly.feinstein commentedon Dec 11, 2019
@Hixie could you clarify this please?
pedromassangocode commentedon Aug 18, 2020
Still valid since the actual documentation does not provide more details about the side effects of updating the text property during build phase.
https://api.flutter.dev/flutter/widgets/TextEditingController/text.html
Hixie commentedon Aug 18, 2020
The reason to not set
textduring build is what the docs say -- it would cause listeners to fire, and you don't want listeners during during build because they might call setState, or do other things, that would invalidate the current build. In general, the build phase should have no business logic at all -- it should have no side effects, the build method is just a function that maps current state to widgets.feinstein commentedon Aug 18, 2020
@Hixie this is a very general recommendation for Flutter that I see often, is it written on any docs so we can link it for the
text, for people (specially inexperienced) that want to learn more?This way we keep the docs small and don't repeat it all over the place.
Hixie commentedon Aug 18, 2020
Hmm, I can't think of anything where we say that. We really should. We should add it to the State.build and StatelessWidget.build API docs, for sure...
feinstein commentedon Aug 18, 2020
Agreed. Do you want me to open an issue about it, or do we track it here?
Hixie commentedon Aug 18, 2020
We can fix it as part of this issue.
huycozy commentedon Nov 16, 2022
This issue is reproducible on the latest
stableandmasterchannels.flutter/packages/flutter/lib/src/widgets/editable_text.dart
Lines 137 to 140 in 78951b0
https://api.flutter.dev/flutter/widgets/TextEditingController/text.html
theprantadutta commentedon May 13, 2026
Hi @Hixie — would it be useful if I took this on with the scope you described upthread ("We can fix it as part of this issue")? My plan:
TextEditingController.text's dartdoc to explain the why — setting it during build fires listeners which may callsetStateor otherwise invalidate the in-progress build — rather than only describing the symptom.build" guidance toState.buildandStatelessWidget.builddartdoc, since you mentioned that doesn't live anywhere else yet.Happy to defer if someone's already on this. Otherwise I'll draft a PR and link back here.