Skip to content

Make the flag "listen" of "Provider.of" default to "false" if called when the widget tree is not building #236

Description

@rrousselGit

Problem:

It is too easy to forget to specify listen: false on a click handler / ...
This causes undesired effects, where after an event handler, the handler widget suddenly rebuilds too often.

Solution:

Since event handlers are always called when the widget tree isn't building, we can automatically infer what listen should be

Consequence:

RaisedButton(
  onPressed: () {
    Provider.of<Whatever>(context); 
  }
)

^ This code will now break.
Before, it caused the widget that creates RaisedButton to rebuild when Whatever changes.

Now, no rebuild will be caused.

For production code, this is usually not an issue.
Where this has an impact, on the other hand, is for tests.

If you previously called Provider.of after a tester.pumpWidgets to test if something was rebuilding, then your test may now fail.

Metadata

Metadata

Assignees

No one assigned

    Labels

    breakingrequires a breaking changeenhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions