Do you want to present a simple modal picker to the user or just show a nice feedback to a user action? In this tutorial you will learn how to use the showModalBottomSheet function.
Let’s start by creating a simple bottom sheet, with a text and a button. As you can see to close a modal bottom sheet you will use the
.pop() function of the Navigator, as you do when closing
Let’s add some fanciness and sound the top corners of our bottom sheet, this is incredibly easy, you just need to add the
shape parameter to the
showModalBottomSheet function, specifying the shape that we want to use.
Now we will do a more complex example, we will display in the bottom sheet a list of 100 elements, and the sheet will expand/collapse while the user scrolls through the list. To do so we will use the DraggableScrollableSheet widget.
This widget has been created to do this types of sheet, it has a builder function that exposes a
ScrollController that we will need to use in our ListView to keep the scrolling of the list in sync with the state of the bottom sheet.
In this case we’re also passing the index of the list tile pressed in the pop function, so we could use it later. It will be the result of the
Future of the
showModalBottomSheet function, and we’re retrieving it awaiting on