Visitar URL original
[animations] Exposed clipBehavior for Opencontainer (#241) · flutter/packages@9c38ae4 · GitHub
Skip to content

Commit 9c38ae4

Browse files
authored
[animations] Exposed clipBehavior for Opencontainer (#241)
1 parent fda7ed4 commit 9c38ae4

3 files changed

Lines changed: 68 additions & 1 deletion

File tree

‎AUTHORS‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55

66
Google Inc.
77
Britannio Jarrett <britanniojarrett@gmail.com>
8+
Sarbagya Dhaubanjar <mail@sarbagyastha.com.np>

‎packages/animations/lib/src/open_container.dart‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class OpenContainer<T extends Object?> extends StatefulWidget {
9898
this.transitionType = ContainerTransitionType.fade,
9999
this.useRootNavigator = false,
100100
this.routeSettings,
101+
this.clipBehavior = Clip.antiAlias,
101102
}) : super(key: key);
102103

103104
/// Background color of the container while it is closed.
@@ -250,6 +251,15 @@ class OpenContainer<T extends Object?> extends StatefulWidget {
250251
/// Provides additional data to the [openBuilder] route pushed by the Navigator.
251252
final RouteSettings? routeSettings;
252253

254+
/// The [closedBuilder] will be clipped (or not) according to this option.
255+
///
256+
/// Defaults to [Clip.antiAlias], and must not be null.
257+
///
258+
/// See also:
259+
///
260+
/// * [Material.clipBehavior], which is used to implement this property.
261+
final Clip clipBehavior;
262+
253263
@override
254264
_OpenContainerState<T> createState() => _OpenContainerState<T>();
255265
}
@@ -302,7 +312,7 @@ class _OpenContainerState<T> extends State<OpenContainer<T?>> {
302312
child: GestureDetector(
303313
onTap: widget.tappable ? openContainer : null,
304314
child: Material(
305-
clipBehavior: Clip.antiAlias,
315+
clipBehavior: widget.clipBehavior,
306316
color: widget.closedColor,
307317
elevation: widget.closedElevation,
308318
shape: widget.closedShape,

‎packages/animations/test/open_container_test.dart‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,62 @@ void main() {
15721572
expect(value, isTrue);
15731573
});
15741574

1575+
testWidgets('closedBuilder has anti-alias clip by default',
1576+
(WidgetTester tester) async {
1577+
final GlobalKey closedBuilderKey = GlobalKey();
1578+
final Widget openContainer = OpenContainer(
1579+
closedBuilder: (BuildContext context, VoidCallback action) {
1580+
return Text('Close', key: closedBuilderKey);
1581+
},
1582+
openBuilder:
1583+
(BuildContext context, CloseContainerActionCallback<bool> action) {
1584+
return const Text('Open');
1585+
},
1586+
);
1587+
1588+
await tester.pumpWidget(
1589+
_boilerplate(child: openContainer),
1590+
);
1591+
1592+
final Finder closedBuilderMaterial = find
1593+
.ancestor(
1594+
of: find.byKey(closedBuilderKey),
1595+
matching: find.byType(Material),
1596+
)
1597+
.first;
1598+
1599+
final Material material = tester.widget<Material>(closedBuilderMaterial);
1600+
expect(material.clipBehavior, Clip.antiAlias);
1601+
});
1602+
1603+
testWidgets('closedBuilder has no clip', (WidgetTester tester) async {
1604+
final GlobalKey closedBuilderKey = GlobalKey();
1605+
final Widget openContainer = OpenContainer(
1606+
closedBuilder: (BuildContext context, VoidCallback action) {
1607+
return Text('Close', key: closedBuilderKey);
1608+
},
1609+
openBuilder:
1610+
(BuildContext context, CloseContainerActionCallback<bool> action) {
1611+
return const Text('Open');
1612+
},
1613+
clipBehavior: Clip.none,
1614+
);
1615+
1616+
await tester.pumpWidget(
1617+
_boilerplate(child: openContainer),
1618+
);
1619+
1620+
final Finder closedBuilderMaterial = find
1621+
.ancestor(
1622+
of: find.byKey(closedBuilderKey),
1623+
matching: find.byType(Material),
1624+
)
1625+
.first;
1626+
1627+
final Material material = tester.widget<Material>(closedBuilderMaterial);
1628+
expect(material.clipBehavior, Clip.none);
1629+
});
1630+
15751631
Widget _createRootNavigatorTest({
15761632
required Key appKey,
15771633
required Key nestedNavigatorKey,

0 commit comments

Comments
 (0)