Julien
Julien

Reputation: 11

Flutter overlay is moving

I'm asking how to disable Overlays to move when a Scaffold.of(context).showSnackBar is called like on my video below. The same thing is happening when the keyboard appear. Sometime the blue floattingButton (+) don't come back to it's original position :-(

Thx in advance.

Problem animation

Upvotes: 1

Views: 638

Answers (1)

chemamolins
chemamolins

Reputation: 20548

The FloatingActionButton going up when the Scaffold is displayed is something common to all default implementations.

Give a look to the "Bootom app bar" demo in the Gallery app. Press on the search button and you will see it coming up. Or just add a Scaffold to the app that is built with flutter create command.

This happens because of the way the FAB button is placed on the screen and the effect of displaying the Snackbar by the Scaffold.

The FAB button is displayed at the bottom of the content area of the Scaffold content. When the content area is shrinked to include the BottomAppBar, the FAB goes up with it. It has nothing to do with Overlay.

You have two options:

  1. Either you create your own versión of the FAB which is not controlled by the Scaffold.
  2. Or you hack the Scaffold so the size of the SnackBar is not taken into account.

For this second option you can try the following:

  • Go to the file /lib/src/material/scaffold.dart in your flutter installation and look for the line with the code snackBarSize: snackBarSize, inside the _ScaffoldLayout class.
  • Replace it with snackBarSize: Size(0.0, 0.0),

You will see that the FAB stays in its place.

Upvotes: 1

Related Questions