Flutter Widgets 08 | Scaffold

NieBin
flutteropen
Published in
5 min readJan 22, 2019

In this tutorial, I will tell you how to use the Scaffold and more in the flutter.

Before Start

The scaffold is so important to use in the flutter and I use it so frequently. So we must know how to use it in the right way. We have used this for all of our pages. It is a widget that used to contain our other widget. So let’s look at a sample use.

We have used the appBar, the body is a Widget, you can use whatever widget you want. We just use the Container to show a Text. So it will show as follows.

Constructor

So before we start our tutorial we should know the constructor of the Scaffold.

floatingActionButton

This will show a button at the bottom of the screen. You can custom your own Widget, but usually, you can use the FloatingActionButton. Let's look at the code as follows.

If you want the button to show in the bottom-center, you can change the floatingActionButtonLocation to FloatingActionButtonLocation.centerFloat.It is easy, other location will retain to you as an exercise.

The floatingActionButtonAnimator will change the animation of this button. This is about the animation, I will tell you in the animation part in the next time.

persistentFooterButtons

If you set this parameter, it will show these widgets at the bottom of the Scaffold. You need to know that this parameter is a List. Let's look at the code as below.

The persistentFooterButtons part will show below the floatingButtonpart.

drawer

This parameter will draw a drawer in the left of the screen. When you click the menu on the left, I will show a drawer to you. Usually, we put a Drawer widget here, if you want to put other widgets here, it doesn't matter, but you should custom your own drawer. So let's look at the constructor of the Drawer to see how to use it.

We know the elevation controls the shadow of the widget, the child is a common widget. The semanticLabel is told before. It is just a string to describe the widget, often with voice. So let's use it.

We click the menu widget to show the drawer, but if we want to show by our custom button, what can we do? there are two choices to do.

1. Use the key

So we can define a key to the Scaffold.

And set the key.

In the part of the persistentFooterButtons, we have two buttons, we call the openDrawer function in the first one.

So, when we click the first one button, it will show the drawer.

2. Use the Context

We can make a Builder to surround a Button.

It will show as below when you click the plus and forward. it will show the drawer.

The endDrawer is the same but with different direction and location. So I do not give the example.

bottomNavigationBar

This is very common in our real app. It shows that it is a widget, but usually, we use the BottomNavigationBar. It will show them at the bottom of the screen to switch different pages.

bottomSheet

This is a dialog shown at the bottom of the screen but above the bottomNavigationBar and persistentFooterButtons. You can use BottomSheet directly as follows.

If you use like thebottomSheet: _bottomSheet(),It will show as follows.

Also, you can call it initiative. But be careful, if you want to use these code below, you should close the bottom before. Then call the function.

backgroundColor & primary

The backgroundColor is easy. Just change its background color. The primary parameter will make the padding-top of the Scaffold with the status bar to be zero. When set the primary = false, the screen will scroll up. Let's see the code and see the effect.

Conclusion

Today, we have learned the Scaffold, this is a very important widget. There are some widgets, such as the Drawer,BottomNavigationBar,BottomSheet,FloatingActionButton,AppBar,persistentFooterButtons to construct our Scaffold. Hope you have learned how to use them.

Thanks for your reading.

The End.

The whole code in Github: https://github.com/FlutterOpen/ebook

--

--