current position:Home>[flutter component collection] divider | August update challenge
[flutter component collection] divider | August update challenge
2022-01-27 04:18:07 【Zhang Feng Jie te lie】
Preface :
This is my participation 8 The fourth of the yuegengwen challenge 18 God , Check out the activity details :8 Yuegengwen challenge . For the Nuggets August is more challenging
, I'm going to choose... This month 31
A component that has not been described before , Conduct a comprehensive analysis and attribute Introduction . These articles will serve as Flutter Component collection
Important material for . I hope we can keep going , Your support will be my greatest motivation ~
This series | Component article | list |
---|---|---|
1.NotificationListener | 2.Dismissible | 3.Switch |
4.Scrollbar | 5.ClipPath | 6.CupertinoActivityIndicator |
7.Opacity | 8.FadeTransition | 9. AnimatedOpacity |
10. FadeInImage | 11. Offstage | 12. TickerMode |
13. Visibility | 14. Padding | 15. AnimatedContainer |
16.CircleAvatar | 17.PhysicalShape | 18.Divider [ this paper ] |
One 、 know Divider Components
Divider
Components are familiar to everyone , It's a horizontal dividing line , You can specify the height 、 thickness 、 Color 、 Margin . What are these attributes by default , How to uniformly set default values ,Divider
How is the source code of the component implemented ? This article will introduce in detail .
1. Divider essential information
Here is Divider
Component class Definition
and Construction method
, You can see that it is inherited from StatelessWidget
. There are five optional parameters :
2.Divider Dimensional analysis of
Have a look first Divider
Size characteristics of : Let's go through [w(10,200) - h(0,200)]
Constraints .Divider
Can pass height
Specifies the height of its size area , The width is the maximum value of the parent constraint . notes : [w(a,b) - h(c,d)]
Express , The dimension constraint is wide in a and b Between , High in c and d Between .
class DividerDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ConstrainedBox(
constraints: BoxConstraints(
maxWidth: 200,
minWidth: 10,
maxHeight: 200,
minHeight: 0
),
child: Divider(
height: 10,
),
);
}
}
Copy code
When the constraint is changed to [w(10,200) - h(50,200)]
, It can be seen that Divider
The specified height will be invalid . in other words Divider
The specified height does not necessarily take effect , It will be controlled by the parent region constraints .
class DividerDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ConstrainedBox(
constraints: BoxConstraints(
maxWidth: 200,
minWidth: 10,
maxHeight: 200,
minHeight: 50
),
child: Divider(
height: 10,
),
);
}
}
Copy code
If you pass UnconstrainedBox
Contact parent constraints , that Divider
There is no limit to the width of the component , Will not show . This also shows that the parent's region constraint pair Divider
Components are important .
Through the rendering tree, you can see ,Divider The final size of the rendered object corresponding to the component is Size(0,0)
, This explains why, without constraints ,Divider The component does not display .
class DividerDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ConstrainedBox(
constraints: BoxConstraints(
maxWidth: 200,
minWidth: 10,
maxHeight: 200,
minHeight: 50
),
child: UnconstrainedBox(
child: Divider(
height: 10,
),
),
);
}
}
Copy code
3.Divider Properties of
The meaning of these attributes is very simple , The following code is three split lines .
Property name | type | The default value is | purpose |
---|---|---|---|
height | double | null | Component height |
thickness | double | null | The thread is thick and thin |
indent | double | null | The left margin |
endIndent | double | null | The right margin |
color | Color | null | Line color |
class DividerDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
width: 200,
child: Wrap(
children:[
const Divider(
height: 10,
indent: 20,
endIndent: 20,
thickness: 1,
color: Colors.orange,
),
const Divider(
height: 10,
indent: 10,
endIndent: 10,
thickness: 2,
color: Colors.blueAccent,
),
const Divider(
height: 10,
),
],
),
);
}
}
Copy code
among indent
and endIndent
Can be used for margins like this , You don't need a coat Padding
Realized .
4.Divider Default properties of
If an application needs to specify the default Divider
style , It's obviously troublesome to set it every time you use it .Flutter There are related theme components in DividerTheme
, It maintains DividerThemeData
data . We can go through This component makes its child nodes Divider
Display in the default style . The effect is as follows :
class DividerDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return DividerTheme(
data: DividerThemeData(
color: Colors.orange,
thickness: 1/window.devicePixelRatio,
space: 5
),
child: Container(
width: 200,
child: Wrap(
children:[
const Divider(),
const Divider(),
const Divider(),
],
),
),
);
}
}
Copy code
Two 、 Divider Source code implementation
First , It is StatelessWidget
, Can only rely on other components to build , The core logic is build
In the method .
Another thing to note , In the assertion of the constructor , All four numeric attributes It can't be negative
.
build
The method is also simple , First, through DividerTheme
get data , It can be seen that if the subject is not set , The default height is 16
Logical pixels . That is to say, at this time Divider
It has a certain height of space occupation . The area size passes through SizedBox
Set up , The dividing line is through Container
The bottom edge of the decoration is finished . among indent
and endIndent
Act on margin
attribute , The essence is still through Padding
The margin that the component completes .
Through debugging, you can see the default DividerTheme
The data attribute in is null
, That's the question Divider
What is the default color for ?
stay createBorderSide
In the static method , It can be seen that , If DividerTheme
The color is null
, Will be based on Theme
Medium dividerColor
Set the color .
that Divider
This is the end of the introduction , So this article ends here , Thank you for watching , See you tomorrow ~
copyright notice
author[Zhang Feng Jie te lie],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201270418047722.html
The sidebar is recommended
- Spring IOC container loading process
- [thinking] the difference between singleton mode and static method - object-oriented programming
- Hadoop environment setup (MySQL environment configuration)
- 10 minutes, using node JS creates a real-time early warning system for bad weather!
- Git tool
- Force deduction algorithm - 92 Reverse linked list II
- What is the sub problem of dynamic programming?
- C / C + +: static keyword summary
- Idea does not have the artifacts option when configuring Tomcat
- Anaconda can't open it
guess what you like
-
I don't know how to start this
-
Matlab simulation of transportation optimization algorithm based on PSO
-
MySQL slow log optimization
-
[Vue] as the window is stretched (larger, smaller, wider and higher), the text will not be displayed
-
Popular Linux distributions for embedded computing
-
Suzhou computer research
-
After installing SSL Certificate in Windows + tomcat, the domain name request is not successful. Please answer!!
-
Implementation time output and greetings of jQuery instance
-
The 72 year old uncle became popular. Wu Jing and Guo fan made his story into a film, which made countless dreamers blush
-
How to save computer research
Random recommended
- Springboot implements excel import and export, which is easy to use, and poi can be thrown away
- The final examination subjects of a class are mathematical programming, and the scores are sorted and output from high to low
- Two pronged approach, Tsinghua Professor Pro code JDK and hotspot source code notes, one-time learning to understand
- C + + recursive knapsack problem
- The use of GIT and GitHub and the latest git tutorial are easy to understand -- Video notes of crazy God speaking
- PostgreSQL statement query
- Ignition database test
- Context didn't understand why he got a high salary?, Nginxfair principle
- Bootstrap switch switch control user's guide, springcloud actual combat video
- A list that contains only strings. What other search methods can be used except sequential search
- [matlab path planning] multi ant colony algorithm grid map path planning [including GUI source code 650]
- [matlab path planning] improved genetic algorithm grid map path planning [including source code phase 525]
- Iinternet network path management system
- Appium settings app is not running after 5000ms
- Reactnative foundation - 07 (background image, status bar, statusbar)
- Reactnative foundation - 04 (custom rpx)
- If you want an embedded database (H2, hsql or Derby), please put it on the classpath
- When using stm32g070 Hal library, if you want to write to flash, you must perform an erase. If you don't let it, you can't write continuously.
- Linux checks where the software is installed and what files are installed
- SQL statement fuzzy query and time interval filtering
- 69. Sqrt (x) (c + + problem solving version with vs runnable source program)
- Fresh students are about to graduate. Do you choose Java development or big data?
- Java project: OA management system (java + SSM + bootstrap + MySQL + JSP)
- Titanic passenger survival prediction
- Vectorization of deep learning formula
- Configuration and use of private image warehouse of microservice architect docker
- Relearn JavaScript events
- For someone, delete return 1 and return 0
- How does Java dynamically obtain what type of data is passed? It is used to judge whether the data is the same, dynamic data type
- How does the database cow optimize SQL?
- [data structure] chain structure of binary tree (pre order traversal) (middle order traversal) (post order traversal) (sequence traversal)
- Webpack packaging optimization solution
- 5. Operation element
- Detailed explanation of red and black trees
- redhat7. 9 install database 19C
- Blue Bridge Cup notes: (the given elements are not repeated) complete arrangement (arrangement cannot be repeated, arrangement can be repeated)
- Detailed explanation of springboot default package scanning mechanism and @ componentscan specified scanning path
- How to solve the run-time exception of test times
- Detailed explanation of k8s management tool kubectl
- Android system view memory command