-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
The big advantage of implementing multiple views with a single widget tree and the OverlayPortal proposal is that overlays/views have access to the surrounding inherited widgets at their anchor point in the widget tree. However, some inherited widgets should not flow into a View or OverlayPortal.
Examples of widgets that should not be available:
- the Material widget - a view needs to contain its own Material for buttons to draw splash effects on, it should not draw the splashes in the parent view
- the view metrics from MediaQuery (needs to be split into ViewQuery and PlatformQuery, see Split MediaQuery into ViewQuery and PlatformQuery #115375)
- Navigator - it will be confusing if a sub-view can modify the navigation stack of the parent view, if that's required, the Navigator should be manually injected
- Overlay - subviews need to contain their own Overlay if they want to show something in an overlay. It would be confusing if the subview's text handles and toolbars are drawn into the parent view's overlay
To support this, we could introduce an InheritanceBoundary that View/OverlayPortal could use to stop certain tagged InheritedWidget from propagating to their children. The InheritedWidget itself gets to decide whether it wants to propagate through the boundary or not.
Implementation Idea:
InheritanceBoundary is a mixin on Element that overrides Element._updateInheritance. Since that method is private (and should likely remain so) it needs to be implemented in framework.dart. Instead of just copying the list of inherited widgets from its parent, InheritanceBoundary will only copy the ones that are allowed to flow through the boundary. The InheritedWidget constructor is extended with a stopsAtInheritanceBoundary argument, which defaults to false. For an InheritedWidget subclass, it must be hard-coded to true or false and is not allowed to change. This property is used by the InheritanceBoundary to determine whether a given inherited widget is supposed to flow through the boundary or not.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status