当前位置:网站首页>[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
边栏推荐
- Is it safe to open a stock account by mobile phone? Is it difficult to open an account?
- Getting started with testing - integration testing
- SQL continuous login problem
- How to add the live video function to the website built by your own live video software (build a live video website)
- Exec function of PHP
- How to skip time when closing a socket connection_ Wait status of wait
- Jerry's watch pause [chapter]
- Bluetooth solution | Lenz technology Amazon direct connected magic lantern solution
- 归并排序
- 99 multiplication table
猜你喜欢

SQL training 01
![[leetcode daily question] number of schemes to reconstruct a tree](/img/82/2ed8c9747f9fa36fde4f18cf8966be.jpg)
[leetcode daily question] number of schemes to reconstruct a tree

PMP项目管理概述

LabVIEW generate application (exe) and installer
![[issue 259] uncover how count is executed in MySQL?](/img/bc/ee26eba95f408ea887d6aa06301a0b.jpg)
[issue 259] uncover how count is executed in MySQL?

2022-2028 global CAE engineering service industry research and trend analysis report

allegro 设计中显示网络飞线或关闭网络飞线的方法

Allegro's method of canceling the routing of a good line

Solve the problem that the cursor flashes after clicking a point when measuring the distance in Allegro

Allegro's method of setting network flying line and network color
随机推荐
如何在关闭socket连接的时候跳过TIME_WAIT的等待状态
Summary of several days
Allegro's method of canceling the routing of a good line
Jerry's watch pause [chapter]
PWN beginner level0
蓝桥杯2022初赛——扫雷
使用gdb添加断点的几种方式
层次分析法(AHP)
Synchronous movement state of Jerry's watch [chapter]
50 lectures on practical application of R language (34) - practical application cases of curve separation (with R language code)
The method of displaying or closing the network flying line in Allegro design
Tortoise 没有显示绿色图标
Matlab exercises - image drawing exercises
PHP system function
Is it safe for qiniu school to open an account in 2022?
Altium Designer中从已有的PCB中导出所有元件的封装的方法
PMP商业分析概述
Several ways to add breakpoints using GDB
【一起上水硕系列】最简单的字幕配置
Jerry's monitoring alarm clock [chapter]