Unverified Commit d8e93ffb authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

Add `clipBehavior` to `Snackbar` (#98252)

parent 0b5032a0
......@@ -204,6 +204,7 @@ class SnackBar extends StatefulWidget {
this.animation,
this.onVisible,
this.dismissDirection = DismissDirection.down,
this.clipBehavior = Clip.hardEdge,
}) : assert(elevation == null || elevation >= 0.0),
assert(content != null),
assert(
......@@ -211,6 +212,7 @@ class SnackBar extends StatefulWidget {
'Width and margin can not be used together',
),
assert(duration != null),
assert(clipBehavior != null),
super(key: key);
/// The primary content of the snack bar.
......@@ -336,6 +338,11 @@ class SnackBar extends StatefulWidget {
/// Cannot be null, defaults to [DismissDirection.down].
final DismissDirection dismissDirection;
/// {@macro flutter.material.Material.clipBehavior}
///
/// Defaults to [Clip.hardEdge], and must not be null.
final Clip clipBehavior;
// API for ScaffoldMessengerState.showSnackBar():
/// Creates an animation controller useful for driving a snack bar's entrance and exit animation.
......@@ -367,6 +374,7 @@ class SnackBar extends StatefulWidget {
animation: newAnimation,
onVisible: onVisible,
dismissDirection: dismissDirection,
clipBehavior: clipBehavior,
);
}
......@@ -612,7 +620,10 @@ class _SnackBarState extends State<SnackBar> {
return Hero(
tag: '<SnackBar Hero tag - ${widget.content}>',
child: snackBarTransition,
child: ClipRect(
clipBehavior: widget.clipBehavior,
child: snackBarTransition,
),
);
}
}
......@@ -6,6 +6,8 @@
// machines.
@Tags(<String>['reduced-test-set'])
import 'dart:ui';
import 'package:flutter/foundation.dart' show FlutterExceptionHandler;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
......@@ -2558,6 +2560,38 @@ void main() {
'was set by default.',
);
});
testWidgets('Snackbar by default clips BackdropFilter', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/98205
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: const Scaffold(),
floatingActionButton: FloatingActionButton(onPressed: () {}),
),
));
final ScaffoldMessengerState scaffoldMessengerState = tester.state<ScaffoldMessengerState>(
find.byType(ScaffoldMessenger),
);
scaffoldMessengerState.showSnackBar(SnackBar(
backgroundColor: Colors.transparent,
content: BackdropFilter(
filter: ImageFilter.blur(
sigmaX: 20.0,
sigmaY: 20.0,
),
child: const Text('I am a snack bar.'),
),
duration: const Duration(seconds: 2),
action: SnackBarAction(label: 'ACTION', onPressed: () {}),
behavior: SnackBarBehavior.fixed,
));
await tester.pumpAndSettle();
await tester.tap(find.text('I am a snack bar.'));
await tester.pump(); // start animation
await tester.pump(const Duration(milliseconds: 750));
await expectLater(find.byType(MaterialApp), matchesGoldenFile('snack_bar.goldenTest.backdropFilter.png'));
});
}
/// Start test for "SnackBar dismiss test".
......
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