Unverified Commit 38805a43 authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

Fix `clipBehavior` for `Drawer` with shape and add `clipBehavior` property. (#124104)

parent 9e4b5fb7
...@@ -153,6 +153,7 @@ class Drawer extends StatelessWidget { ...@@ -153,6 +153,7 @@ class Drawer extends StatelessWidget {
this.width, this.width,
this.child, this.child,
this.semanticLabel, this.semanticLabel,
this.clipBehavior,
}) : assert(elevation == null || elevation >= 0.0); }) : assert(elevation == null || elevation >= 0.0);
/// Sets the color of the [Material] that holds all of the [Drawer]'s /// Sets the color of the [Material] that holds all of the [Drawer]'s
...@@ -237,6 +238,14 @@ class Drawer extends StatelessWidget { ...@@ -237,6 +238,14 @@ class Drawer extends StatelessWidget {
/// value is used. /// value is used.
final String? semanticLabel; final String? semanticLabel;
/// {@macro flutter.material.Material.clipBehavior}
///
/// The [clipBehavior] argument specifies how to clip the drawer's [shape].
///
/// If the drawer has a [shape], it defaults to [Clip.hardEdge]. Otherwise,
/// defaults to [Clip.none].
final Clip? clipBehavior;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
assert(debugCheckHasMaterialLocalizations(context)); assert(debugCheckHasMaterialLocalizations(context));
...@@ -255,6 +264,9 @@ class Drawer extends StatelessWidget { ...@@ -255,6 +264,9 @@ class Drawer extends StatelessWidget {
final bool useMaterial3 = Theme.of(context).useMaterial3; final bool useMaterial3 = Theme.of(context).useMaterial3;
final bool isDrawerStart = DrawerController.maybeOf(context)?.alignment != DrawerAlignment.end; final bool isDrawerStart = DrawerController.maybeOf(context)?.alignment != DrawerAlignment.end;
final DrawerThemeData defaults= useMaterial3 ? _DrawerDefaultsM3(context): _DrawerDefaultsM2(context); final DrawerThemeData defaults= useMaterial3 ? _DrawerDefaultsM3(context): _DrawerDefaultsM2(context);
final ShapeBorder? effectiveShape = shape ?? (isDrawerStart
? (drawerTheme.shape ?? defaults.shape)
: (drawerTheme.endShape ?? defaults.endShape));
return Semantics( return Semantics(
scopesRoute: true, scopesRoute: true,
namesRoute: true, namesRoute: true,
...@@ -267,9 +279,8 @@ class Drawer extends StatelessWidget { ...@@ -267,9 +279,8 @@ class Drawer extends StatelessWidget {
elevation: elevation ?? drawerTheme.elevation ?? defaults.elevation!, elevation: elevation ?? drawerTheme.elevation ?? defaults.elevation!,
shadowColor: shadowColor ?? drawerTheme.shadowColor ?? defaults.shadowColor, shadowColor: shadowColor ?? drawerTheme.shadowColor ?? defaults.shadowColor,
surfaceTintColor: surfaceTintColor ?? drawerTheme.surfaceTintColor ?? defaults.surfaceTintColor, surfaceTintColor: surfaceTintColor ?? drawerTheme.surfaceTintColor ?? defaults.surfaceTintColor,
shape: shape ?? (isDrawerStart shape: effectiveShape,
? (drawerTheme.shape ?? defaults.shape) clipBehavior: effectiveShape != null ? (clipBehavior ?? Clip.hardEdge) : Clip.none,
: (drawerTheme.endShape ?? defaults.endShape)),
child: child, child: child,
), ),
), ),
......
...@@ -688,6 +688,57 @@ void main() { ...@@ -688,6 +688,57 @@ void main() {
); );
}); });
testWidgets('Drawer clip behavior', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: true),
home: const Scaffold(
drawer: Drawer(),
),
),
);
final Finder drawerMaterial = find.descendant(
of: find.byType(Drawer),
matching: find.byType(Material),
);
final ScaffoldState state = tester.firstState(find.byType(Scaffold));
// Open the drawer.
state.openDrawer();
await tester.pump();
await tester.pump(const Duration(seconds: 1));
// Test default clip behavior.
Material material = tester.widget<Material>(drawerMaterial);
expect(material.clipBehavior, Clip.hardEdge);
state.closeDrawer();
await tester.pumpAndSettle();
// Provide a custom clip behavior.
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: true),
home: const Scaffold(
drawer: Drawer(
clipBehavior: Clip.antiAlias,
),
),
),
);
// Open the drawer again.
state.openDrawer();
await tester.pump();
await tester.pump(const Duration(seconds: 1));
// Clip behavior is now updated.
material = tester.widget<Material>(drawerMaterial);
expect(material.clipBehavior, Clip.antiAlias);
});
group('Material 2', () { group('Material 2', () {
// Tests that are only relevant for Material 2. Once ThemeData.useMaterial3 // Tests that are only relevant for Material 2. Once ThemeData.useMaterial3
// is turned on by default, these tests can be removed. // is turned on by default, these tests can be removed.
...@@ -732,5 +783,57 @@ void main() { ...@@ -732,5 +783,57 @@ void main() {
material = tester.widget<Material>(drawerMaterial); material = tester.widget<Material>(drawerMaterial);
expect(material.shape, null); expect(material.shape, null);
}); });
testWidgets('Drawer clip behavior', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: const Scaffold(
drawer: Drawer(),
),
),
);
final Finder drawerMaterial = find.descendant(
of: find.byType(Drawer),
matching: find.byType(Material),
);
final ScaffoldState state = tester.firstState(find.byType(Scaffold));
// Open the drawer.
state.openDrawer();
await tester.pump();
await tester.pump(const Duration(seconds: 1));
// Test default clip behavior.
Material material = tester.widget<Material>(drawerMaterial);
expect(material.clipBehavior, Clip.none);
state.closeDrawer();
await tester.pumpAndSettle();
// Provide a shape and custom clip behavior.
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: const Scaffold(
drawer: Drawer(
clipBehavior: Clip.hardEdge,
shape: RoundedRectangleBorder(),
),
),
),
);
// Open the drawer again.
state.openDrawer();
await tester.pump();
await tester.pump(const Duration(seconds: 1));
// Clip behavior is now updated.
material = tester.widget<Material>(drawerMaterial);
expect(material.clipBehavior, Clip.hardEdge);
});
}); });
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment