Unverified Commit 737824db authored by xubaolin's avatar xubaolin Committed by GitHub

snackBar should paint above the bottomSheet (#73558)

parent 68d8c4b3
......@@ -3031,6 +3031,25 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto
'the preferred API instead of the Scaffold methods.'
);
if (_currentBottomSheet != null || _dismissedBottomSheets.isNotEmpty) {
final Widget stack = Stack(
alignment: Alignment.bottomCenter,
children: <Widget>[
..._dismissedBottomSheets,
if (_currentBottomSheet != null) _currentBottomSheet!._widget,
],
);
_addIfNonNull(
children,
stack,
_ScaffoldSlot.bottomSheet,
removeLeftPadding: false,
removeTopPadding: true,
removeRightPadding: false,
removeBottomPadding: _resizeToAvoidBottomInset,
);
}
// SnackBar set by ScaffoldMessenger
if (_messengerSnackBar != null) {
final SnackBarBehavior snackBarBehavior = _messengerSnackBar?._widget.behavior
......@@ -3110,25 +3129,6 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto
);
}
if (_currentBottomSheet != null || _dismissedBottomSheets.isNotEmpty) {
final Widget stack = Stack(
alignment: Alignment.bottomCenter,
children: <Widget>[
..._dismissedBottomSheets,
if (_currentBottomSheet != null) _currentBottomSheet!._widget,
],
);
_addIfNonNull(
children,
stack,
_ScaffoldSlot.bottomSheet,
removeLeftPadding: false,
removeTopPadding: true,
removeRightPadding: false,
removeBottomPadding: _resizeToAvoidBottomInset,
);
}
_addIfNonNull(
children,
_FloatingActionButtonTransition(
......
......@@ -2266,4 +2266,29 @@ void main() {
final AssertionError error = exceptions.first as AssertionError;
expect(error.message, contains('Only one API should be used to manage SnackBars.'));
});
testWidgets('SnackBars should be shown above the bottomSheet', (WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp(
home: Scaffold(
bottomSheet: SizedBox(
width: 200,
height: 50,
child: ColoredBox(
color: Colors.pink,
),
),
),
));
final ScaffoldMessengerState scaffoldMessengerState = tester.state(find.byType(ScaffoldMessenger));
scaffoldMessengerState.showSnackBar(SnackBar(
content: const Text('I love Flutter!'),
duration: const Duration(seconds: 2),
action: SnackBarAction(label: 'ACTION', onPressed: () {}),
behavior: SnackBarBehavior.floating,
));
await tester.pumpAndSettle(); // Have the SnackBar fully animate out.
await expectLater(find.byType(MaterialApp), matchesGoldenFile('snack_bar.goldenTest.workWithBottomSheet.png'));
});
}
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