Unverified Commit 618ab7d2 authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Fix floating snackbar Y (#64268)

parent 0f4d2481
...@@ -578,7 +578,15 @@ class _ScaffoldLayout extends MultiChildLayoutDelegate { ...@@ -578,7 +578,15 @@ class _ScaffoldLayout extends MultiChildLayoutDelegate {
if (floatingActionButtonRect.size != Size.zero && isSnackBarFloating) { if (floatingActionButtonRect.size != Size.zero && isSnackBarFloating) {
snackBarYOffsetBase = floatingActionButtonRect.top; snackBarYOffsetBase = floatingActionButtonRect.top;
} else { } else {
snackBarYOffsetBase = contentBottom; // SnackBarBehavior.fixed applies a SafeArea automatically.
// SnackBarBehavior.floating does not since the positioning is affected
// if there is a FloatingActionButton (see condition above). If there is
// no FAB, make sure we account for safe space when the SnackBar is
// floating.
final double safeYOffsetBase = size.height - minViewPadding.bottom;
snackBarYOffsetBase = isSnackBarFloating
? math.min(contentBottom, safeYOffsetBase)
: contentBottom;
} }
final double xOffset = hasCustomWidth ? (size.width - snackBarWidth) / 2 : 0.0; final double xOffset = hasCustomWidth ? (size.width - snackBarWidth) / 2 : 0.0;
......
...@@ -420,6 +420,53 @@ void main() { ...@@ -420,6 +420,53 @@ void main() {
expect(snackBarBottomRight.dx, 800 - padding); // Device width is 800. expect(snackBarBottomRight.dx, 800 - padding); // Device width is 800.
}); });
testWidgets('SnackbarBehavior.floating is positioned within safe area', (WidgetTester tester) async {
const double viewPadding = 50.0;
const double floatingSnackBarDefaultBottomMargin = 10.0;
await tester.pumpWidget(
MaterialApp(
home: MediaQuery(
data: const MediaQueryData(
// Simulate non-safe area.
viewPadding: EdgeInsets.only(bottom: viewPadding),
),
child: Scaffold(
body: Builder(
builder: (BuildContext context) {
return GestureDetector(
onTap: () {
Scaffold.of(context).showSnackBar(
const SnackBar(
content: Text('I am a snack bar.'),
behavior: SnackBarBehavior.floating,
),
);
},
child: const Text('X'),
);
}
),
),
),
),
);
await tester.tap(find.text('X'));
await tester.pump(); // Start animation
await tester.pump(const Duration(milliseconds: 750));
final Finder materialFinder = find.descendant(
of: find.byType(SnackBar),
matching: find.byType(Material),
);
final Offset snackBarBottomLeft = tester.getBottomLeft(materialFinder);
expect(
snackBarBottomLeft.dy,
// Device height is 600.
600 - viewPadding - floatingSnackBarDefaultBottomMargin,
);
});
testWidgets('Snackbar padding can be customized', (WidgetTester tester) async { testWidgets('Snackbar padding can be customized', (WidgetTester tester) async {
const double padding = 20.0; const double padding = 20.0;
await tester.pumpWidget( await tester.pumpWidget(
......
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