Skip to content

Allow multiple ParentDataWidgets to write to a child #133089

@Piinks

Description

@Piinks

Found in flutter/packages#4746

The KeepAlive ParentDataWidget creates a complication for the proposed TableViewCell, which is also a ParentDataWidget. The actual ParentData of TableViewCell includes the KeepAliveParentDataMixin, so it should be ok for both ParentDataWidgets to contribute to a child's parent data as proposed.

Chatted with @goderbauer about this today.. we think it should be ok to allow this with some assertions

  • The type of ParentData of the child should be compatible with both ParentDataWidgets
    • TableViewParentData extends TwoDimensionalViewportParentData, which mixes in KeepAliveParentDataMixin, so the parentData is compatible with both KeepAlive and TableViewCell
  • The ParentDataWidgets, and the ParentData they write to should be unique
    • KeepAlive uses KeepAliveParentDataMixin, TableViewCell uses TableViewParentData, this would be valid ✅
    • If two Flexible widgets are trying to contribute to one child's ParentData at the same time, this would not be valid since they could end up overwriting each other ❌
  • Applying ParentData should follow the structure of the tree, working from the first ancestor up

This is likely to occur here in framework.dart in RenderObjectElement. We currently assert only one parent can write data, and collect up the 'badAncestors' to assert against:

ParentDataElement<ParentData>? _findAncestorParentDataElement() {

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listframeworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework teamwaiting for PR to land (fixed)A fix is in flight

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions