Add clipBehavior
to Snackbar
(#98252)
This commit is contained in:
parent
0b5032a058
commit
d8e93ffb8b
@ -204,6 +204,7 @@ class SnackBar extends StatefulWidget {
|
|||||||
this.animation,
|
this.animation,
|
||||||
this.onVisible,
|
this.onVisible,
|
||||||
this.dismissDirection = DismissDirection.down,
|
this.dismissDirection = DismissDirection.down,
|
||||||
|
this.clipBehavior = Clip.hardEdge,
|
||||||
}) : assert(elevation == null || elevation >= 0.0),
|
}) : assert(elevation == null || elevation >= 0.0),
|
||||||
assert(content != null),
|
assert(content != null),
|
||||||
assert(
|
assert(
|
||||||
@ -211,6 +212,7 @@ class SnackBar extends StatefulWidget {
|
|||||||
'Width and margin can not be used together',
|
'Width and margin can not be used together',
|
||||||
),
|
),
|
||||||
assert(duration != null),
|
assert(duration != null),
|
||||||
|
assert(clipBehavior != null),
|
||||||
super(key: key);
|
super(key: key);
|
||||||
|
|
||||||
/// The primary content of the snack bar.
|
/// The primary content of the snack bar.
|
||||||
@ -336,6 +338,11 @@ class SnackBar extends StatefulWidget {
|
|||||||
/// Cannot be null, defaults to [DismissDirection.down].
|
/// Cannot be null, defaults to [DismissDirection.down].
|
||||||
final DismissDirection dismissDirection;
|
final DismissDirection dismissDirection;
|
||||||
|
|
||||||
|
/// {@macro flutter.material.Material.clipBehavior}
|
||||||
|
///
|
||||||
|
/// Defaults to [Clip.hardEdge], and must not be null.
|
||||||
|
final Clip clipBehavior;
|
||||||
|
|
||||||
// API for ScaffoldMessengerState.showSnackBar():
|
// API for ScaffoldMessengerState.showSnackBar():
|
||||||
|
|
||||||
/// Creates an animation controller useful for driving a snack bar's entrance and exit animation.
|
/// 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,
|
animation: newAnimation,
|
||||||
onVisible: onVisible,
|
onVisible: onVisible,
|
||||||
dismissDirection: dismissDirection,
|
dismissDirection: dismissDirection,
|
||||||
|
clipBehavior: clipBehavior,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -612,7 +620,10 @@ class _SnackBarState extends State<SnackBar> {
|
|||||||
|
|
||||||
return Hero(
|
return Hero(
|
||||||
tag: '<SnackBar Hero tag - ${widget.content}>',
|
tag: '<SnackBar Hero tag - ${widget.content}>',
|
||||||
|
child: ClipRect(
|
||||||
|
clipBehavior: widget.clipBehavior,
|
||||||
child: snackBarTransition,
|
child: snackBarTransition,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
// machines.
|
// machines.
|
||||||
@Tags(<String>['reduced-test-set'])
|
@Tags(<String>['reduced-test-set'])
|
||||||
|
|
||||||
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart' show FlutterExceptionHandler;
|
import 'package:flutter/foundation.dart' show FlutterExceptionHandler;
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
@ -2558,6 +2560,38 @@ void main() {
|
|||||||
'was set by default.',
|
'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".
|
/// Start test for "SnackBar dismiss test".
|
||||||
|
Loading…
x
Reference in New Issue
Block a user