Skip to content

Commit

Permalink
[animations] Exposed clipBehavior for Opencontainer (flutter#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarbagyastha authored Feb 10, 2021
1 parent fda7ed4 commit 9c38ae4
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@

Google Inc.
Britannio Jarrett <[email protected]>
Sarbagya Dhaubanjar <[email protected]>
12 changes: 11 additions & 1 deletion packages/animations/lib/src/open_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class OpenContainer<T extends Object?> extends StatefulWidget {
this.transitionType = ContainerTransitionType.fade,
this.useRootNavigator = false,
this.routeSettings,
this.clipBehavior = Clip.antiAlias,
}) : super(key: key);

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

/// The [closedBuilder] will be clipped (or not) according to this option.
///
/// Defaults to [Clip.antiAlias], and must not be null.
///
/// See also:
///
/// * [Material.clipBehavior], which is used to implement this property.
final Clip clipBehavior;

@override
_OpenContainerState<T> createState() => _OpenContainerState<T>();
}
Expand Down Expand Up @@ -302,7 +312,7 @@ class _OpenContainerState<T> extends State<OpenContainer<T?>> {
child: GestureDetector(
onTap: widget.tappable ? openContainer : null,
child: Material(
clipBehavior: Clip.antiAlias,
clipBehavior: widget.clipBehavior,
color: widget.closedColor,
elevation: widget.closedElevation,
shape: widget.closedShape,
Expand Down
56 changes: 56 additions & 0 deletions packages/animations/test/open_container_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1572,6 +1572,62 @@ void main() {
expect(value, isTrue);
});

testWidgets('closedBuilder has anti-alias clip by default',
(WidgetTester tester) async {
final GlobalKey closedBuilderKey = GlobalKey();
final Widget openContainer = OpenContainer(
closedBuilder: (BuildContext context, VoidCallback action) {
return Text('Close', key: closedBuilderKey);
},
openBuilder:
(BuildContext context, CloseContainerActionCallback<bool> action) {
return const Text('Open');
},
);

await tester.pumpWidget(
_boilerplate(child: openContainer),
);

final Finder closedBuilderMaterial = find
.ancestor(
of: find.byKey(closedBuilderKey),
matching: find.byType(Material),
)
.first;

final Material material = tester.widget<Material>(closedBuilderMaterial);
expect(material.clipBehavior, Clip.antiAlias);
});

testWidgets('closedBuilder has no clip', (WidgetTester tester) async {
final GlobalKey closedBuilderKey = GlobalKey();
final Widget openContainer = OpenContainer(
closedBuilder: (BuildContext context, VoidCallback action) {
return Text('Close', key: closedBuilderKey);
},
openBuilder:
(BuildContext context, CloseContainerActionCallback<bool> action) {
return const Text('Open');
},
clipBehavior: Clip.none,
);

await tester.pumpWidget(
_boilerplate(child: openContainer),
);

final Finder closedBuilderMaterial = find
.ancestor(
of: find.byKey(closedBuilderKey),
matching: find.byType(Material),
)
.first;

final Material material = tester.widget<Material>(closedBuilderMaterial);
expect(material.clipBehavior, Clip.none);
});

Widget _createRootNavigatorTest({
required Key appKey,
required Key nestedNavigatorKey,
Expand Down

0 comments on commit 9c38ae4

Please sign in to comment.