Skip to content

Commit f6d83d3

Browse files
committed
[animations] Add support for custom shadows to OpenContainer (#62475)
1 parent 4763d4f commit f6d83d3

File tree

5 files changed

+312
-83
lines changed

5 files changed

+312
-83
lines changed

packages/animations/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.2.0
2+
3+
* Adds support for custom `closedShadows` and `openShadows` to `OpenContainer`.
4+
* Fixes a layout overflow issue in the `_ExampleSingleTile` within the example app.
5+
16
## 2.1.2
27

38
* Updates minimum supported SDK version to Flutter 3.35/Dart 3.9.

packages/animations/example/lib/container_transition.dart

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ class _OpenContainerTransformDemoState
128128
body: ListView(
129129
padding: const EdgeInsets.all(8.0),
130130
children: <Widget>[
131+
_CustomShadowExampleCard(transitionType: _transitionType),
132+
const SizedBox(height: 16.0),
131133
_OpenContainerWrapper(
132134
transitionType: _transitionType,
133135
closedBuilder: (BuildContext _, VoidCallback openContainer) {
@@ -388,7 +390,7 @@ class _ExampleSingleTile extends StatelessWidget {
388390

389391
return _InkWellOverlay(
390392
openContainer: openContainer,
391-
height: height,
393+
constraints: const BoxConstraints(minHeight: height),
392394
child: Row(
393395
children: <Widget>[
394396
Container(
@@ -423,21 +425,73 @@ class _ExampleSingleTile extends StatelessWidget {
423425
}
424426

425427
class _InkWellOverlay extends StatelessWidget {
426-
const _InkWellOverlay({this.openContainer, this.height, this.child});
428+
const _InkWellOverlay({
429+
this.openContainer,
430+
this.height,
431+
this.constraints,
432+
this.child,
433+
});
427434

428435
final VoidCallback? openContainer;
429436
final double? height;
437+
final BoxConstraints? constraints;
430438
final Widget? child;
431439

432440
@override
433441
Widget build(BuildContext context) {
434-
return SizedBox(
442+
return Container(
435443
height: height,
444+
constraints: constraints,
436445
child: InkWell(onTap: openContainer, child: child),
437446
);
438447
}
439448
}
440449

450+
class _CustomShadowExampleCard extends StatelessWidget {
451+
const _CustomShadowExampleCard({required this.transitionType});
452+
453+
final ContainerTransitionType transitionType;
454+
455+
@override
456+
Widget build(BuildContext context) {
457+
return OpenContainer(
458+
transitionType: transitionType,
459+
openBuilder: (BuildContext context, VoidCallback _) {
460+
return const _DetailsPage();
461+
},
462+
closedElevation: 0.0,
463+
closedShadows: const <BoxShadow>[
464+
BoxShadow(
465+
color: Colors.blue,
466+
blurRadius: 15.0,
467+
offset: Offset(0.0, 5.0),
468+
),
469+
],
470+
openShadows: const <BoxShadow>[
471+
BoxShadow(
472+
color: Colors.red,
473+
blurRadius: 40.0,
474+
spreadRadius: 10.0,
475+
offset: Offset(0.0, 10.0),
476+
),
477+
],
478+
closedBuilder: (BuildContext context, VoidCallback openContainer) {
479+
return _InkWellOverlay(
480+
openContainer: openContainer,
481+
height: 100,
482+
child: const Center(
483+
child: Text(
484+
'Custom shadows',
485+
textAlign: TextAlign.center,
486+
style: TextStyle(fontWeight: FontWeight.bold),
487+
),
488+
),
489+
);
490+
},
491+
);
492+
}
493+
}
494+
441495
class _DetailsPage extends StatelessWidget {
442496
const _DetailsPage({this.includeMarkAsDoneButton = true});
443497

0 commit comments

Comments
 (0)