[animations] Exposed clipBehavior for Opencontainer (#241)

This commit is contained in:
Sarbagya Dhaubanjar
2021-02-11 04:23:49 +05:45
committed by GitHub
parent fda7ed4703
commit 9c38ae4ef6
3 changed files with 68 additions and 1 deletions

View File

@ -5,3 +5,4 @@
Google Inc.
Britannio Jarrett <britanniojarrett@gmail.com>
Sarbagya Dhaubanjar <mail@sarbagyastha.com.np>

View File

@ -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.
@ -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>();
}
@ -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,

View File

@ -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,