当前位置:网站首页>Flutter series part: detailed explanation of GridView layout commonly used in flutter
Flutter series part: detailed explanation of GridView layout commonly used in flutter
2022-06-28 13:01:00 【51CTO】
brief introduction
GridView Is a grid layout , If the subassemblies in the filling process are beyond the scope of the display , that GridView It will scroll automatically .
Because of this scrolling feature , therefore GridView Is a very easy to use Widget. Today, let's explore GridView This layout Secrets of components .
GridView Detailed explanation
GridView Is a scrollable view, That is to say ScrollView, in fact GridView Inherited from BoxScrollView:
And its parent class BoxScrollView, It is inherited from ScrollView:
You can see BoxScrollView Is an abstract class , It has two subclasses , These are what we are going to talk about today GridView And the next issue ListView.
The difference between the two components is GridView It's a 2D Layout , and ListView It's a linear layout Layout .
As BoxScrollView Subclasses of ,GridView Need to achieve buildChildLayout The method is as follows :
here GridView Returned a SliverGrid, This SliverGrid There are two properties in , Namely childrenDelegate and gridDelegate.
among gridDelegate It's a SliverGridDelegate Example , Used to control sub components in GridView Layout in .
childrenDelegate It's a SliverChildDelegate Example , Used to generate GridView The subcomponents in .
These two attributes are GridView In the constructor of , We will explain it in detail next .
GridView Constructor for
GridView There are many constructors , The first is a full - parameter constructor that contains all the parameters :
In this constructor , You need to pass in a custom gridDelegate, So in the constructor gridDelegate yes required state :
It's mentioned above that GridView Two custom attributes in , The other one is childrenDelegate, This attribute is constructed from other parameters passed in , As shown below :
Another one GridView The constructor for is called GridView.builder, The difference between this constructor and the default constructor is childrenDelegate Different implementations of , Let's see GridView.builder in childrenDelegate The implementation of the :
Compared with ,GridView.builder Medium childrenDelegate Two more parameters , Namely itemBuilder and itemCount.
So what are these two parameters used for ?
Consider one that has many chil Of GridView, In order to improve GridView Display performance , We can't take out all of them at once child Element , Instead, it will be dynamically created and drawn in scrolling , And here it is itemCount Namely child Maximum capacity of .
and itemBuilder Is a dynamic creation child Creator of , Thus, dynamic creation child The needs of .
The next constructor is called GridView.custom, Because it's called custom, So this constructor's SliverGridDelegate and SliverChildDelegate It's all customizable , In other words, these two parameters can be passed in from the outside , So these two parameters are both necessary :
GirdView There is also a constructor called GridView.count, there count Refer to GridView You can specify cross axis The number of components that can be included in the , So here gridDelegate It USES one SliverGridDelegateWithFixedCrossAxisCount:
You can set crossAxisCount Value .
the last one GridView The constructor for is called GridView.extent, It and count The constructor for is very similar to , however extent What is provided is a maximum cross-axis extent, Instead of a fixed count value , So here gridDelegate It's a SliverGridDelegateWithMaxCrossAxisExtent object :
How do you understand that ? for instance , If GirdView It is vertical rolling , And its width yes 400 pixels, If this time maxCrossAxisExtent Set to 120, So a row can only have three columns . We can adjust maxCrossAxisExtent Value , To adjust view The display of .
We can select the corresponding constructor according to our needs , So as to meet our different needs .
GridView Use
With GridView Constructor for ,GridView It's easy to use .
For example, we dynamically create a containing image Of child, Form a gridView:
there buildChild Used to generate a containing Widget Of list, As shown below :
Finally, the GridViewApp Put it in Scaffold Of body Run in :
Finally, we can get the following image :

Here we are using GridView.extent Constructors , You can try other constructors by yourself .
summary
GridView Is a component that we often use in our daily work , I hope you can master .
Examples of this article : https://github.com/ddean2009/learn-flutter.git
边栏推荐
- I ² C. SMBus, pmbus relationships
- ASP. NET CORE Study06
- Which securities company is the best and safest? How to open an account is the safest
- Realization of a springboard machine
- pytorch主要模块
- 电脑无线网络不显示网络列表应该如何解决
- 自定义MySQL连接池
- Digital twin energy system, creating a "perspective" in the low-carbon era
- 泛海微FH511单片机IC方案小家电LED照明MCU丝印FH511
- manjaro easyconnecy报错:libgtk-x11-2.0.so.0: cannot open shared object file: No such file or directory
猜你喜欢

Mysq 8.0 launched histogram, which greatly improved the performance!

FH511+TP4333组成一个户外移动电源照明野营灯方案。

Understand leveldb write operation

一文搞懂leveldb写操作

一文抄 10 篇!韩国发表的顶级会议论文被曝抄袭,第一作者是“原罪”?

Copying open source for basic software is not advisable. Self reliance is the right way

10万美元AI竞赛:寻找大模型做得“更烂”的任务

【历史上的今天】6 月 28 日:马斯克诞生;微软推出 Office 365;蔡氏电路的发明者出生

$100000 AI competition: the task of finding "worse" big models

Stm32f1 and stm32cubeide programming example - matrix keyboard driver
随机推荐
The Research Report of Analysys' 2022 China Banking privacy computing platform supplier strength matrix analysis' was officially launched
k3s一键安装脚本
Jerry's wif interferes with Bluetooth [chapter]
Go语学习笔记 - gorm使用 - 数据库配置、表新增 | Web框架Gin(七)
How to install SSL certificates in Microsoft Exchange 2010
中二青年付杰的逆袭故事:从二本生到 ICLR 杰出论文奖,我用了20年
##测试bug常用“Redmine”
Go language learning notes - Gorm usage - database configuration, table addition | web framework gin (VII)
group_ Concat learning and configuration
async-validator.js数据校验器
Ipetronik data acquisition equipment and softing q-vision software are committed to ADAS test scheme
How to find opportunities in a bear market?
微服务稳定性保障
June 28, 2022 Daily: Lecun's latest paper: the road to autonomous machine intelligence
Tencent tangdaosheng: facing the new world of digital and real integration, developers are the most important "architects"
matlab plotyy 坐标轴设置,[转载]Matlab plotyy画双纵坐标图实例[通俗易懂]
腾讯确认QQ大规模盗号,iPhone14无缘Type-C,第四大运营商5G正式放号,今日更多大新闻在此...
弹性盒子自动换行小Demo
Vscode如何设置自动保存代码
Performance test-01-introduction