Flutter Widgets 17 | SimpleDialog&AlertDialog
In this tutorial, you will learn how to use the SimpleDialog in the flutter.
What we will learn?
Before Start
We will create a page to contain our code.
It will show the picture as follows.
Simple Use
The dialog is very common in our app, it will show short messages to us to our choice. Let’s see an example below.
It will show you like this.
Constructor
Let’s look at its constructor.
The constructor is very easy to know because we have known the types of its parameters. I will give an example to them.
titlePadding&contentPadding
The title
is a widget, the children
is a list of the widgets, this is easy to understand. The titlePadding
controls the padding of the title
, the contentPadding
controls the padding of the children
. Let's see an example.
Let’s see the effect of our code.
backgroundColor& elevation
The backgroundColor
is a Color
, the elevation controls the shadow of the widget, those are common parameters that we have used them before. I just give an example.
It will show like this. The color of the background will change to RED
.The shadow becomes less.
shape
The is also the same as the shape
of Container
, you can check it in that article. I just give you an example.
It will show as below.
AlertDialog
The AlertDialog
is similar to the SimpleDialog
. Let's look at the constructor.
We compare these two constructors of the AlertDialog
and the SimpleDialog
. The main difference between them is that the AlertDialog
has more parameters, which are the titleTextStyle, content, contentTextStyle
, and actions
, than the SimpleDialog
. So let's look an example.
It will show like this.
Conclusion
From this article, you can learn how to implement the dialog with the SimpleDialog
widget. It is easy to use, so I don't give the detail of many parameters. If you a newer, you should read the other articles before.
Thanks for reading.
The End.
The whole code in Github: https://github.com/FlutterOpen/ebook