当前位置:网站首页>[flutter topic] 66 diagram basic constraints box (I) yyds dry goods inventory
[flutter topic] 66 diagram basic constraints box (I) yyds dry goods inventory
2022-06-29 03:09:00 【A Ze young monk】
In the process of learning , In order to adjust or adapt Widget Big hour , Will be set Widget Or nest some constraints Widget; Let's learn about this series of constraints Box;
SizedBox
Source code analysis
Analyze the source code to know ,SizeBox Inherited from SingleChildRenderObjectWidget Only sub Child The storage of does not provide update logic ; And SizedBox Provides a variety of ways to use , Try the dishes one by one ;
Case study
1. SizedBox({ Key key, this.width, this.height, Widget child })
SizedBox Customizable width and height, When limiting width and height , Son Widget No matter how wide or high , Are filled by default ; By setting double.infinity Fill in the parent class Widget Wide and high , Note that there should be restrictions on the parent class at this time , It's not infinite width and height ; When width and height Not set time , According to Widget Size display ;

2. SizedBox.expand({ Key key, Widget child })
.expand It's a convenient way , Default width and height Are all double.infinity, Fill the entire parent class Widget;

3. SizedBox.shrink({ Key key, Widget child })
.shrink It's also a convenient way , but width and height Are all 0.0, Regardless of son Widget How many settings are not displayed ; I haven't figured out the application scenario of this method yet ;
4. SizedBox.fromSize({ Key key, Widget child, Size size })
.fromSize The convenient method is basically the same as the basic construction method , It's just width and height from Size encapsulation , This method can achieve the same effect as the basic method ;

ConstrainedBox
Source code analysis
Analyze the source code to know ,ConstrainedBox Also inherited from SingleChildRenderObjectWidget; The way of constraint is mainly to constraints The operation of ; be relative to SizedBox More flexible constraints ;
Case study
1. BoxConstraints()
BoxConstraints The construction method of can set the four properties of maximum, minimum width and height , It can be flexibly used in the actual scene ; The size of the constraint is in accordance with minWidth <= child.width <= maxWidth && minHeight <= child.Height <= maxHeight, When we don't set the width and height dimensions ,minWidth = 0.0 && minHeight = 0.0 && maxWidth = double.infinity && maxHeight = double.infinity;

2. BoxConstraints.tight(Size size)
.tight The construction method needs to pass a fixed size Size among minWidth == maxWidth == size.width && maxWidth == maxHeight == size.height; Regardless of son Widget Set the width and height according to Size Width and height constraints ;

3. BoxConstraints.tightFor()
I understand .tightFor The way is .tight Refinement of methods , You can customize width and height; If width and height are not set , Then the maximum width and height is infinite , The minimum width and height is 0.0; If the width and height are set, the constraint is carried out according to the set size ;

4. BoxConstraints.tightForFinite()
.tightForFinite And .tightFor similar , The default maximum width and height is infinite , The minimum width and height is 0.0, It determines whether the set width and height are infinite , No double.infinity be minWidth == maxWidth == width && maxWidth == maxHeight == height Constraint ;

5. BoxConstraints.loose()
.loose Way to limit a given Size size ,minWidth / minHeight Are all 0.0, The maximum width and height is Size size ; The overall constraint is determined by Size Limit , Actual display and sub Widget Size related ;

6. BoxConstraints.expand()
Most of the .expand The method is filling , Default fill parent Widget, If width and height are not set , Default minWidth == maxWidth == double.infinity && minHeight == maxHeight == double.infinity, When using, pay attention to the parent constraint ;

Flutter Provides a variety of constraints Box, All roads lead to Rome , The same effect can be achieved in many ways , But I think we should know more about , Try the best possible solution ; It's a piece of cake Box The series of research is still very simple , If there are mistakes, please give more guidance !
source : Little monk aze
边栏推荐
- 2022-2028 global long wave infrared camera and camera core industry research and trend analysis report
- Movement state change of monitoring device of Jerry's watch [chapter]
- LinkedList学习
- Double click events and click events
- SQL training 01
- sql训练01
- Merge sort
- 双击事件与单击事件的那些事
- How to add the live video function to the website built by your own live video software (build a live video website)
- Concise words tell about technical people who must master basic IT knowledge and skills. Part 1
猜你喜欢
![[linear algebra] 1.2 total permutation and commutation](/img/04/18fc358c6c426e10c8598bcee9cd43.png)
[linear algebra] 1.2 total permutation and commutation

2022-2028 global bubble CPAP system industry survey and trend analysis report

2022-2028 global secondary butyl lithium industry research and trend analysis report

Leetcode daily question - 324 Swing sort II

The method of exporting packages of all components from existing PCBs in Altium Designer

2022-2028 global industrial lithium chloride industry research and trend analysis report

音响是如何把微弱声音放大呢
![Jerry's watch begins to move [chapter]](/img/85/232da1c1f8dddb3af1e564e4a0fc53.jpg)
Jerry's watch begins to move [chapter]

In depth analysis of Apache bookkeeper series: Part 3 - reading principle

【一起上水硕系列】Day 6-强肝学术论文!最细解释!
随机推荐
PWN attack and defense world guess_ num
Synchronous real-time data of Jerry's watch [chapter]
50 lectures on practical application of R language (34) - practical application cases of curve separation (with R language code)
Redu.us took the initiative to transform, and the operation leader of China's charging pile emerged
There's a mystery behind the little login
Oracle recovery tools actual batch bad block repair
Tu ne peux pas comprendre le feu?
Concise words tell about technical people who must master basic IT knowledge and skills. Part 1
Nvisual helps integrators transform
FPGA(八)RTL代码之四(基本电路设计1)
2022-2028 global CAE engineering service industry research and trend analysis report
2022-2028 global pneumatic test probe industry survey and trend analysis report
leetcode 统计无向图中无法互相到达点对数
2022-2028 global MWIR camera industry research and trend analysis report
Only in the past four years, Microsoft finally gave it up!
How to add the live video function to the website built by your own live video software (build a live video website)
[線性代數] 1.1 二階與三階行列式
The thinkphp5.1 runtime file has been changed to 777 permission, but cannot be written
线程池是什么老鸡?
PAT甲级 A1057 Stack