[Animations] Add support for custom shadows to OpenContainer (#62475)#11401
[Animations] Add support for custom shadows to OpenContainer (#62475)#11401moepanda wants to merge 1 commit intoflutter:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds support for custom closedShadows and openShadows to the OpenContainer widget, enabling custom shadow animations during transitions. It also fixes a layout overflow in the example app by transitioning from a fixed height to minimum height constraints and includes new tests to verify shadow behavior. A review comment suggests conditionally wrapping the Material widget with DecoratedBox only when custom shadows are provided to avoid unnecessary widgets in the tree.
| child: DecoratedBox( | ||
| decoration: ShapeDecoration( | ||
| shape: widget.closedShape, | ||
| shadows: widget.closedShadows, | ||
| ), |
There was a problem hiding this comment.
Wrapping the Material widget with a DecoratedBox even when closedShadows is null adds an unnecessary widget to the tree. While the performance impact is likely negligible, you could conditionally wrap it to keep the tree cleaner in the default case.
child: widget.closedShadows == null
? Material(
clipBehavior: widget.clipBehavior,
color: widget.closedColor,
elevation: widget.closedElevation,
shape: widget.closedShape,
child: Builder(
key: _closedBuilderKey,
builder: (BuildContext context) {
return widget.closedBuilder(context, openContainer);
},
),
)
: DecoratedBox(
decoration: ShapeDecoration(
shape: widget.closedShape,
shadows: widget.closedShadows,
),
child: Material(
clipBehavior: widget.clipBehavior,
color: widget.closedColor,
elevation: 0.0,
shape: widget.closedShape,
child: Builder(
key: _closedBuilderKey,
builder: (BuildContext context) {
return widget.closedBuilder(context, openContainer);
},
),
),
),
Summary
This PR adds support for custom
BoxShadowto theOpenContainerwidget. This allows developers to specifyclosedShadowsandopenShadowsto create more advanced and visually appealing transitions that go beyond the standard materialelevation._ExampleSingleTileby replacing the fixed height with responsive constraints, ensuring the example remains stable across different system font sizes and shadow distributions.Motivation
Currently,
OpenContaineronly supports a numericelevationproperty, which limits modern UI designs requiring colored or multi-layered shadows. This PR also refactors the internal rendering hierarchy to move the shadow decoration outside the clipping surface, fixing a legacy issue where custom shadows were clipped byMaterial.Issues
Fixes flutter/flutter#62475
Pre-Review Checklist
[animations]///).