Skip to content

setState() doesn't trigger build() #49245

@feinstein

Description

@feinstein

I have a rather complicated widget, but it's general functionality is easy to explain. It starts to listen to a Stream in initState() and when the Stream emits a new value, it calls setState(). I know I could use a StreamBuilder, but this way I can wait for a Future to complete and then call setState(), whereas with StreamBuilder I need to return a new Widget synchronously.

AFAIK every call to setState() should trigger a build(), but when I go to InteliJ IDEA and click to Debug, sometimes the first time this Steam emits a value, setState() is called, but build() isn't. I checked mounted and it's true.

The docs don't say anything about the possibility of calling setState() and build() doesn't getting called right afterwards. Is this a bug on setState() or are the docs missing something?

My Flutter version:

Flutter 1.12.13+hotfix.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 27321eb (6 weeks ago) • 2019-12-10 18:15:01 -0800
Engine • revision 2994f7e
Tools • Dart 2.7.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    frameworkflutter/packages/flutter repository. See also f: labels.in triagePresently being triaged by the triage team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions