In this tutorial, I will tell you about the RaiseButton in the flutter.
Before Start
As tutorial before, we should create a page to contain our code. Because we have so many parameters, we need many examples to describe this. So I create a page that can scroll, we just put our tutorial code in the children list. The code is below.
The onPressed parameter is necessary, its value is a function, I just put a print statement here. About the child, I put a Text here. It will show as below.If you click this button, it will print pressed in the console.
Constructor
When we want to use some widgets, don't forget to look at the constructor carefully.
We have learned how to use the onPressed, child, so I will talk about the others below.
onHighlightChanged
This parameter is a function as the onPressed parameter. If we set this parameter, when we click down or up the button, the onHighlightChanged will be called. The definition is as follows. So it is just a function with bool parameter.
Color textColor,//When we put the child as a Text, this color will set to it.Color disabledTextColor,Color color,Color disabledColor,Color highlightColor,Color splashColor,
Let's set the different value to see its effect. You should know when onPressed: null,the button will be disable. So you can see the disabledColor/disabledTextColor.
When calling in our children list in RaiseButtonPage. You can see as follows. The first one you can press,and when you click the button, the animation color is the BLUE_DEEP, it is the splashColor . If you click the button and stain a moment, the background of the button will change to RED, it is the highlightColor. But the second will not be clicked.
textTheme
The textTheme also controls the color text, but it depends on the theme in the our app. I set like this.
About the textTheme its type is an enum. Let's look at its definition.
enumButtonTextTheme {/// Button text is black or white depending on [ThemeData.brightness]. normal,/// Button text is [ThemeData.accentColor]. accent,/// Button text is based on [ThemeData.primaryColor]. primary,}
The description is easy to understand, let's see the effect.
In the last RaiseButton, I add the textTheme parameter to compare. When we see the picture, we know that it will take precedence to show the textTheme if it is set.
I know the textColor controls the same thing in our widget. So what its priority. Let's compare these three parameters.
So, about the precedence, we have the result textColor > textTheme > colorBrightness.
elevation
There are three parameters about the elevation: elevation,disabledElevation,highlightElevation. They are the same function use for different part, they all control shadow of the button. The elevation controls the normal state, disabledElevation to the disable state, highlightElevation to the highlight state. Let's look at an example.
This parameter controls the distance inside of the child. We have learned the detail of the padding in Widgets 01 | Container. So I just give an example.
This parameter is very nice, it can change the shape of the button. We have used it before, but just a simple one in the Container, this time we will learn more detail about this parameter. We know the shape is the ShapeBorder. It is an abstract class, so we can't use it directly. So we must find its children class. Let's look at the table.These all are its subclass. But BoxBorder,InputBorder are the abstract class, their subclass is in the same line. If you want to use shape, you can use all of them,except the abstract class.
So how to use them. Let's see an example with each border.
When the content has not enough space, then we will decide to clip some contents. So the clipBehavior will control this situation. Let's look at an example first.
We can see that except the first one, the others will be cut the surplus part. So what difference between them? Now I will amplify the picture and show the different.The hardEdge obvious has some saw-tooth, and other two have a smooth edge.
Let's look at their main different about its speed and quality. Let's look at the following picture.
Our example shows the last two are similar, so if you want a smooth edge and consider the deal speed, we recommend you using the antiAlias.
Conclusion
Today we have learned the RaiseButton. This widget has many parameters. The main knowledge contains how to use the onPressed,color,elevation,shape. Especially, we have listed its use of all shape.