Skip to content

Clarify/improve dependOnInheritedWidgetOfExactType documentation? #73423

Description

@wujek-srujek

Use case

In a few places in docs for BuildContext the following can be found (formatting/newlines mine) (e.g. https://api.flutter.dev/flutter/widgets/BuildContext/dependOnInheritedWidgetOfExactType.html):

This method should not be called from widget constructors or from State.initState methods, because those
methods would not get called again if the inherited value were to change. To ensure that the widget correctly
updates itself when the inherited value changes, only call this (directly or indirectly) from build methods,
layout and paint callbacks, or from State.didChangeDependencies.

Would it make sense to mention why exactly initState is excluded? Does this mean that such methods somehow save which method they were called from, and call them back when necessary? Why doesn't Flutter just call the build method of whatever Widget's context the method was called on, why would it try to call the method that the dependOnInheritedWidgetOfExactType (or others with the same caveat) method call was made from?

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listd: api docsIssues with https://api.flutter.dev/frameworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions