Widgets 02 | Text
This time I will tell you more about the Text.It fits from beginners to experts.
Last updated
This time I will tell you more about the Text.It fits from beginners to experts.
Last updated
This problem is very fooling but needs to know, The text show our string and it also is a widget in the flutter, we can use it as a common widget, so be careful about their parameters.
In the widgets 01, we create a page to show our container, also we create a page show our Text
. The way of creating a page is the same as before, you do not care about this, you just focus on the Text
widget now. We will put them all in the children
as follows.
Then, we can put our Text into the children
to continue our tutorial.
You must make a custom to look at the constructor of the widgets before using it.
The this.data
is where we put the String
, this is easy to understand, we do not talk about this. the style
is most common to use. this.locale
control its language,this time I don't plan to talk about it, I will write another article to explain it. So let's talk about the parameters one by one.
Let's look at its definition.
It is a TextStyle
class, look at its definition,so many important parameters are here,such as the fontSize
, color
, height
.
The function of these parameters is a definition with its name. The color
parameter control the color of Text
.The fontSize
controls its font size. We just show an example for simple param.
We just change the parameters,they will show as follows.
Above code, we can learn how to use color
,fontSize
and background
t,the background is a Paint that controls the color or other things, I don't want to expand this for more detail.
We can see that the foreground
is also as the background
above, so just use the Paint
,the ..
is a special operator in the flutter.
Is same as below.
We just code as follows.
The paint draw the Text
with the foreground, be careful that we can't use the color parameter with this, so you can only choose one parameter.
You can see the definition, the class is FontWeight
, you can use its constant with a fore definition. We will use the FontWeight.w700
, it represents bold text. The other constants you can find in the class FontWeight
,remain to you.
We know the type is FontStyle
, we use its only two constants.As follows, this example will show an italic text.
The parameter will control the distance between the letter inside a word. For example, the word Hello
if set this param, the distance between H,e,l,l,o
will depend on this param.
The parameter controls the distance between the two words, I will set two different wordSpacing
to compare.
When we see the definition of the shadows
, we can see this.
The Shadow
constructor is below.
The offset
is the direction from the origin point of the widget, the blurRadius
is the distance of the blurred space.
So let's see an example.
In this part, I will tell three params:decoration, decorationColor, decorationStyle
. They draw the same line show in the Text, the decoration
controls the location, decorationColor
control the color, decorationStyle
control the shape. The definition is below.
Let's see an example.
This parameter changes the typeface for the font. It is a bit difficult, but be patient.
First, we should download a typeface file on the web and in our project, I put into the assets/font
. You should know the folders are created by myself, you can do that too.
Then, config the pubspec.yaml
file in our project,as I note with the red rectangle and paste the config as well.
Finally, we can use the font name manigu
as we set above.
It is easy for use, if you want more detail about the typeface to use, you can click this link. So far, we finish the using of TextStyle
, let's look at the other using.
This param controls the Text
location in the parent widget, I will show you it in a Container
. The TextAlign
constants are below, I just use the end
to show.
Normally, we draw the Text
from left from right, but we can change it with the textDirection
parameter.
This param will control the whether or not the show all content when there is not enough space for the text to show. If true means that it will show the all content, otherwise not show.
When there is not enough place to show, how we hand the end part, the overflow is a choice to handle this, above we end just cover the other part, but we can end with three points like follows, you also can use clip
,fade
.
Also, you can use the maxLines
to limit the space, in above part we can see the Text show two lines when there is no space in the horizontal direction.
When we want to make the Text
larger or more little, we can use the fontSize
to change its size. But there is another choice to change its scale, the textScaleFactor
. It depends on the fontSize
, for example, when we set fontSize=10 ,textScaleFactor =2
, the real scale of the Text
will be equal to 20, means that the real-scale= fontSize*textScaleFactor
for the Text
.
Today we learn how to use the Text, the most common used param is the style, it mainly controls the Text itself, but some other parameters are controlled with its parent widget. But you needn't know all of them, it's just used with your requirement.
Thanks for your reading!
The end.
Facebook Page
GitHub
Flutter Open
NieBin
NieBin
1
2
3
left
center
right
start
justify
end
Facebook Page
QQ Group
GitHub
Flutter Open
NieBin
963828159
NieBin