Skip to content

Commit

Permalink
Revert "Add error message and documentation when a SnackBar is off …
Browse files Browse the repository at this point in the history
…screen" (flutter#104843)
  • Loading branch information
Piinks authored and godofredoc committed Jun 3, 2022
1 parent 562df08 commit 5acfecb
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 221 deletions.

This file was deleted.

This file was deleted.

43 changes: 0 additions & 43 deletions packages/flutter/lib/src/material/scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -264,23 +264,6 @@ class ScaffoldMessengerState extends State<ScaffoldMessenger> with TickerProvide
///
/// ** See code in examples/api/lib/material/scaffold/scaffold_messenger_state.show_snack_bar.0.dart **
/// {@end-tool}
///
/// ## Relative positioning of floating SnackBars
///
/// A [SnackBar] with [SnackBar.behavior] set to [SnackBarBehavior.floating] is
/// positioned above the widgets provided to [Scaffold.floatingActionButton],
/// [Scaffold.persistentFooterButtons], and [Scaffold.bottomNavigationBar].
/// If some or all of these widgets take up enough space such that the SnackBar
/// would not be visible when positioned above them, an error will be thrown.
/// In this case, consider constraining the size of these widgets to allow room for
/// the SnackBar to be visible.
///
/// {@tool dartpad}
/// Here is an example showing that a floating [SnackBar] appears above [Scaffold.floatingActionButton].
///
/// ** See code in examples/api/lib/material/scaffold/scaffold_messenger_state.show_snack_bar.1.dart **
/// {@end-tool}
///
ScaffoldFeatureController<SnackBar, SnackBarClosedReason> showSnackBar(SnackBar snackBar) {
assert(
_scaffolds.isNotEmpty,
Expand Down Expand Up @@ -1135,32 +1118,6 @@ class _ScaffoldLayout extends MultiChildLayoutDelegate {

final double xOffset = hasCustomWidth ? (size.width - snackBarWidth!) / 2 : 0.0;
positionChild(_ScaffoldSlot.snackBar, Offset(xOffset, snackBarYOffsetBase - snackBarSize.height));

assert((){
// Whether a floating SnackBar has been offsetted too high.
//
// To improve the developper experience, this assert is done after the call to positionChild.
// if we assert sooner the SnackBar is visible because its defaults position is (0,0) and
// it can cause confusion to the user as the error message states that the SnackBar is off screen.
if (isSnackBarFloating) {
final bool snackBarVisible = (snackBarYOffsetBase - snackBarSize.height) > 0;
if (!snackBarVisible) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('Floating SnackBar presented off screen.'),
ErrorDescription(
'A SnackBar with behavior property set to SnackBarBehavior.floating is fully '
'or partially off screen because some or all the widgets provided to '
'Scaffold.floatingActionButton, Scaffold.persistentFooterButtons and '
'Scaffold.bottomNavigationBar take up too much vertical space.\n'
),
ErrorHint(
'Consider constraining the size of these widgets to allow room for the SnackBar to be visible.',
),
]);
}
}
return true;
}());
}

if (hasChild(_ScaffoldSlot.statusBar)) {
Expand Down
66 changes: 0 additions & 66 deletions packages/flutter/test/material/snack_bar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1652,72 +1652,6 @@ void main() {
},
);

void openFloatingSnackBar(WidgetTester tester) {
final ScaffoldMessengerState scaffoldMessengerState = tester.state(find.byType(ScaffoldMessenger));
scaffoldMessengerState.showSnackBar(
const SnackBar(
content: Text('SnackBar text'),
behavior: SnackBarBehavior.floating,
),
);
}

void expectSnackBarNotVisibleError(WidgetTester tester) {
final AssertionError exception = tester.takeException() as AssertionError;
const String message = 'Floating SnackBar presented off screen.\n'
'A SnackBar with behavior property set to SnackBarBehavior.floating is fully '
'or partially off screen because some or all the widgets provided to '
'Scaffold.floatingActionButton, Scaffold.persistentFooterButtons and '
'Scaffold.bottomNavigationBar take up too much vertical space.\n'
'Consider constraining the size of these widgets to allow room for the SnackBar to be visible.';
expect(exception.message, message);
}

testWidgets('Snackbar with SnackBarBehavior.floating will assert when offsetted too high by a large Scaffold.floatingActionButton', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/84263
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
floatingActionButton: Container(),
),
),
);

openFloatingSnackBar(tester);
await tester.pumpAndSettle(); // Have the SnackBar fully animate out.
expectSnackBarNotVisibleError(tester);
});

testWidgets('Snackbar with SnackBarBehavior.floating will assert when offsetted too high by a large Scaffold.persistentFooterButtons', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/84263
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
persistentFooterButtons: <Widget>[SizedBox(height: 1000)],
),
),
);

openFloatingSnackBar(tester);
await tester.pumpAndSettle(); // Have the SnackBar fully animate out.
expectSnackBarNotVisibleError(tester);
});

testWidgets('Snackbar with SnackBarBehavior.floating will assert when offsetted too high by a large Scaffold.bottomNavigationBar', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/84263
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
bottomNavigationBar: SizedBox(height: 1000),
),
),
);

openFloatingSnackBar(tester);
await tester.pumpAndSettle(); // Have the SnackBar fully animate out.
expectSnackBarNotVisibleError(tester);
});

testWidgets(
'SnackBar has correct end padding when it contains an action with fixed behavior',
(WidgetTester tester) async {
Expand Down

0 comments on commit 5acfecb

Please sign in to comment.