当前位置:网站首页>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
边栏推荐
- 腾讯确认QQ大规模盗号,iPhone14无缘Type-C,第四大运营商5G正式放号,今日更多大新闻在此...
- scratch旅行相册 电子学会图形化编程scratch等级考试一级真题和答案解析2022年6月
- Copying open source for basic software is not advisable. Self reliance is the right way
- 认识启动函数,找到用户入口
- ASP. NET CORE Study01
- Xiaobai's e-commerce business is very important to choose the right mall system!
- pytorch基础
- Can ArcGIS Pro directly connect PostgreSQL and edit layer elements
- 华泰证券手机app下载 怎么办理开户最安全
- 微服务稳定性保障
猜你喜欢

Fastposter v2.8.4 release e-commerce poster generator

百度APP 基于Pipeline as Code的持续集成实践

##测试bug常用“Redmine”
![BUUCTF:[WUSTCTF2020]朴实无华](/img/0f/a7973d3f7593f2464e48609e27d7bd.png)
BUUCTF:[WUSTCTF2020]朴实无华

Online JSON to plaintext tool
![[MySQL from introduction to mastery] [advanced part] (III) creation of MySQL users_ Modification_ Delete and password settings](/img/9c/2a0eb8f5ec03aebbe231dbdb388eca.png)
[MySQL from introduction to mastery] [advanced part] (III) creation of MySQL users_ Modification_ Delete and password settings

一款自动生成单元测试的 IDEA 插件,开发效率提升 70% 以上!

如何在熊市中寻找机会?

pytorch基础

Copying open source for basic software is not advisable. Self reliance is the right way
随机推荐
认识启动函数,找到用户入口
Flink流处理API大合集:掌握所有flink流处理技术,看这一篇就够了
Hundreds of lines of code to implement a JSON parser
数据分析-启动子进化分析
fastposter v2.8.4 发布 电商海报生成器
Siyuan official paid synchronization Guide
flex布局中的align-content属性
中二青年付杰的逆袭故事:从二本生到 ICLR 杰出论文奖,我用了20年
【云原生】自助报表和BI能做这么多事?
开源项目维权成功案例: Spug 开源运维平台成功维权
flink核心之watermarker
Matplotlib_ Study01
After failing in the college entrance examination, he entered Harbin Institute of technology, but stayed in the university after graduation to be an "Explorer". Ding Xiao: scientific research is accum
ASP. NET CORE Study02
arcgis pro 可以实现直连postgresql,编辑图层要素吗
2. 01背包问题
从pdb源码到frame帧对象
The white paper on the panorama of the digital economy and the digitalization of consumer finance were released
证券账户开户哪家的费率低 怎么办理开户最安全
k3s一键安装脚本