'Floating SnackBar presented off screen' assertion in a Scaffold
Floating SnackBar presented off screen.Short answer
A floating SnackBar is placed above the Scaffold's bottom widgets. The debug check fails when its top edge would land above the screen. The floating action button, persistentFooterButtons, bottomNavigationBar or the SnackBar itself is taking too much height. Shrink the widget that is too tall.
Fix it fast
1Find out which cause you have
Find which of the Scaffold's bottom widgets are set, then check how tall each is. The error names floatingActionButton, persistentFooterButtons and bottomNavigationBar as the usual users of the space.
grep -rn "floatingActionButton\|persistentFooterButtons\|bottomNavigationBar\|SnackBarBehavior.floating" lib2Match what you see, then jump to its fix
- 1
Floating SnackBar presented off screen, and the screen has a large bottom bar or footerbottomNavigationBar or persistentFooterButtons is too tallFix - 2
Floating SnackBar presented off screen, only on screens with a FABAn oversized floating action buttonFix - 3
Floating SnackBar presented off screen after a long messageThe SnackBar content is itself taller than the free spaceFix
- 1
What does the error look like?
Floating SnackBar presented off screen.Consider constraining the size of these widgets to allow room for the SnackBar to be visible.
Cause 1 of 3
bottomNavigationBar or persistentFooterButtons is too tall
1Check
A floating SnackBar appears above other Scaffold widgets, including a bottom navigation bar. If these take too much of the height, the snack bar cannot fit above them.
grep -rn "bottomNavigationBar\|persistentFooterButtons" lib2Fix
Constrain the height of the bottom widget, for example in small landscape layouts.
bottomNavigationBar: ConstrainedBox(
constraints: const BoxConstraints(maxHeight: 80),
child: const MyNavBar(),
),3Verify
Show the SnackBar again.
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Saved'), behavior: SnackBarBehavior.floating));Confirmed by raw.githubusercontent.com
Cause 2 of 3
An oversized floating action button
1Check
The SnackBar is positioned from the top edge of the floating action button when it is shown above it. A very tall FAB or a custom widget placed as the FAB moves that edge up.
grep -rn "floatingActionButton" lib2Fix
Keep the FAB within its normal size, or constrain the widget you pass as floatingActionButton.
floatingActionButton: SizedBox(
height: 56,
child: FloatingActionButton(onPressed: onAdd, child: const Icon(Icons.add)),
),3Verify
Hot restart, show the SnackBar and watch the debug console for the assertion.
ScaffoldMessenger.of(context).showSnackBar(snackBar);Confirmed by api.flutter.dev
Cause 3 of 3
The SnackBar content is itself taller than the free space
1Check
The check fails when the SnackBar's top edge (its base position minus its own height) would be negative. A long multi-line message on a screen with little free height can cause that.
grep -rn "SnackBar(" lib2Fix
Shorten the message and limit its lines.
SnackBar(
behavior: SnackBarBehavior.floating,
content: const Text('Saved', maxLines: 2, overflow: TextOverflow.ellipsis),
)3Verify
Show the same SnackBar on the smallest screen you support.
ScaffoldMessenger.of(context).showSnackBar(snackBar);Confirmed by raw.githubusercontent.com
How do I stop it coming back?
- Test SnackBars on the smallest screen and in landscape, not only on a tall phone.
- Keep bottom bars and footers at their standard heights.
- Keep SnackBar messages short.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Qist BazaarA buy-now-pay-later marketplace built from a blank repo, now past 100K downloads on Google Play.
- SessionBirdAn omnichannel engagement suite in Flutter: campaigns, chatbot, tickets, analytics and live calling.
Related fixes
Mobile apps
AudioCache has no play method after updating audioplayers
The method 'play' isn't defined for the type 'AudioCache'.
Since audioplayers 1.0, AudioCache only turns asset files into local files and caches them.
2 causes, each with a fixMobile apps
Flutter Bloc throws that emit was called after the event handler completed
emit was called after an event handler completed normally.
Each on<Event> handler gets its own Emitter, and it stops working the moment the handler's returned Future completes.
2 causes, each with a fixMobile apps
analysis_options.yaml: the URI it includes can't be found
include_file_not_found
The analyzer reports include_file_not_found when the file named after include: in analysis_options.yaml does not resolve.
2 causes, each with a fixMobile apps
Dart error: the body might complete normally and return null for a non-nullable type
body_might_complete_normally
Dart found a path through your function or callback that reaches the closing brace without a return.
3 causes, each with a fixMobile apps
Dart throws ConcurrentModificationError while looping over a list
ConcurrentModificationError
Dart throws this when a collection changes size while something iterates it.
2 causes, each with a fixMobile apps
Dart cannot turn a compact timestamp like 20201101153000 into a DateTime
FormatException: Invalid date format
DateTime.parse accepts a subset of ISO 8601, and a time part must be introduced by T or a space.
2 causes, each with a fix