Skip to content

[Animations] Add support for custom shadows to OpenContainer (#62475)#11401

Open
moepanda wants to merge 2 commits intoflutter:mainfrom
moepanda:fix_open_container_shadow
Open

[Animations] Add support for custom shadows to OpenContainer (#62475)#11401
moepanda wants to merge 2 commits intoflutter:mainfrom
moepanda:fix_open_container_shadow

Conversation

@moepanda
Copy link
Copy Markdown

Summary

This PR adds support for custom BoxShadow to the OpenContainer widget. This allows developers to specify closedShadows and openShadows to create more advanced and visually appealing transitions that go beyond the standard material elevation.

  • Fixes a legacy layout overflow issue in _ExampleSingleTile by replacing the fixed height with responsive constraints, ensuring the example remains stable across different system font sizes and shadow distributions.

Motivation

Currently, OpenContainer only supports a numeric elevation property, 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 by Material.

Issues

Fixes flutter/flutter#62475

Pre-Review Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [AI contribution guidelines] and understand my responsibilities.
  • I read the [Tree Hygiene] page, which explains my responsibilities.
  • I read and followed the [relevant style guides] and ran [the auto-formatter].
  • I signed the [CLA]. (Reminder: Please ensure you've signed it!)
  • The title of the PR starts with [animations]
  • I linked to at least one issue that this PR fixes in the description above.
  • I followed [the version and CHANGELOG instructions].
  • I updated/added any relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.

@github-actions github-actions bot added p: animations triage-framework Should be looked at in framework triage labels Mar 31, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/animations/lib/src/open_container.dart Outdated
@moepanda moepanda force-pushed the fix_open_container_shadow branch 3 times, most recently from 2f3b47b to 88d57a1 Compare April 1, 2026 05:42
@moepanda moepanda force-pushed the fix_open_container_shadow branch from 88d57a1 to f6d83d3 Compare April 1, 2026 06:15
Copy link
Copy Markdown
Member

@hannah-hyj hannah-hyj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you for fixing the layout overflow issue too!

@moepanda
Copy link
Copy Markdown
Author

moepanda commented Apr 9, 2026

LGTM, thank you for fixing the layout overflow issue too!

Thank you! Glad to help.

@stuartmorgan-g
Copy link
Copy Markdown
Collaborator

From triage: @hannah-hyj Please add a second reviewer familiar with the package, so this can get the secondary review for landing.

@hannah-hyj hannah-hyj requested a review from QuncCccccc April 14, 2026 22:35
Copy link
Copy Markdown
Contributor

@QuncCccccc QuncCccccc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! Overall looks good! Just left one comment for adding an additional unit test.

final Widget material = Material(
clipBehavior: widget.clipBehavior,
color: widget.closedColor,
elevation: widget.closedShadows == null ? widget.closedElevation : 0.0,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for my learning, why do we need to set elevation to 0.0 when closedShadows is non-null.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We set elevation to 0.0 so the shadow comes from a single source when custom shadows are provided.
In this case the visual shadow is drawn by the wrapping DecoratedBox, so keeping Material.elevation would stack the framework shadow on top of the custom BoxShadows.
The same rule is applied in the fully-open state as well.

animationDuration: Duration.zero,
color: colorTween!.evaluate(animation),
shape: _shapeTween.evaluate(curvedAnimation),
elevation: _elevationTween.evaluate(curvedAnimation),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to check currentShadows here like above?

Copy link
Copy Markdown
Author

@moepanda moepanda Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentional. The elevation tween already accounts for whether custom shadows are provided on either side, so mixed cases can smoothly transition between Material elevation and custom shadows. If we zeroed elevation whenever currentShadows is non-null, the transition would become abrupt in those mixed cases.

expect(dataClosed.rect, dataTransitionDone.rect);
});

testWidgets('Custom shadows work', (WidgetTester tester) async {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test case for when one of the shadow properties is null and the other is provided? This would ensure the fallback to elevation behavior is verified and doesn't break in the future.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I added mixed null/non-null shadow test coverage for both directions to lock in the elevation fallback behavior during the transition.

Add coverage for null/non-null shadow combinations in OpenContainer.
This verifies the elevation fallback behavior during mixed shadow transitions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p: animations triage-framework Should be looked at in framework triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenContainer add customize shadow support

4 participants