Flutter floatingActionButton on modal bottom (without scaffold)

2,909

You can use a Stack widget with Positioned widget

Stack(
 children: [
  Material(...),
  Positioned(...) //put a button inside and position it with bottom and right
)
Share:
2,909
Jesse James Portnoy
Author by

Jesse James Portnoy

Programmer, packager, sys admin and a firm believer in FOSS.

Updated on December 27, 2022

Comments

  • Jesse James Portnoy
    Jesse James Portnoy over 1 year

    I have a situation in which I want a modal bottom sheet to be visible upon tapping a widget. This code works correctly (from the widget, which is basically a "card"):

        return Container(
            color: Colors.white,
            margin: EdgeInsets.symmetric(horizontal: 5.0),
            child: Material(
                child: InkWell(
                onTap: () {
                        showMaterialModalBottomSheet(
                                    expand: false,
                                    context: context,
                                    builder: (context) =>
                                        customiseItemScreen(item: this.item,),
                                    );
    
                },
                ...
                ...
    
    

    However, I'd also like to display a floating action button in the customiseItemScreen widget. When there's a scaffold involved, it's easy, to wit:

    floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
    floatingActionButton:
    ...
    ...
    

    But since customiseItemScreen returns a Material (without a scaffold), the above members do not exist. Is there a better way to go about this or a solution that I may be missing with the existing code?

    Thanks in advance,

  • Jesse James Portnoy
    Jesse James Portnoy about 3 years
    Thanks @captain-web, I was hoping to avoid the Positioned widget but it's in fact what I ended up doing as I couldn't find a better solution. For future copy pasters: dart Positioned( bottom: 10, child: yourChildWidget() ),