当前位置:网站首页>Flutter GridView Demo
Flutter GridView Demo
2022-04-22 07:37:00 【GuoXuan_CHN】
GridView
代码
///2019.4.20 By GX
Widget _buildRechargeGridView() {
List<Widget> list = [];
for (int i = 0; i < (infoList == null ? 0 : this.infoList.length); i++) {
///初始化每个单元
Widget view = _buildGridUnit();
list.add(view);
}
return Container(
height: (MediaQuery.of(context).size.width) / 3 + 44,
width: MediaQuery.of(context).size.width,
padding: EdgeInsets.only(
left: getWidthFromRatio(context, 20),
right: getWidthFromRatio(context, 20)),
child: GridView(
///机型适配,如有需要,变更SliverGridDelegateWithFixedCrossAxisCount
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: (MediaQuery.of(context).size.width) / 3,
mainAxisSpacing: 22,
crossAxisSpacing: 20,
childAspectRatio: 2,
),
children: list,
),
);
}
代码说明
infoList
infoList 是对GridView每个单元的初始化信息的List。在您的代码中应该是从网络获取或是其他方式。
_buildGridUnit()
_buildGridUnit 是return一个 widget的私有函数,根据需求在函数中创建GridView的通用单元布局
属性说明
SliverGridDelegateWithMaxCrossAxisExtent
const SliverGridDelegateWithMaxCrossAxisExtent({
@required this.maxCrossAxisExtent, //每个Unit有多宽
this.mainAxisSpacing = 0.0,//主轴方向间距
this.crossAxisSpacing = 0.0,//纵轴方向间距
this.childAspectRatio = 1.0,//主轴纵轴缩放比例
})
SliverGridDelegateWithFixedCrossAxisCount
const SliverGridDelegateWithFixedCrossAxisCount({
@required this.crossAxisCount,//每行几个
this.mainAxisSpacing = 0.0,//主轴方向间距
this.crossAxisSpacing = 0.0,//纵轴方向间距
this.childAspectRatio = 1.0,//主轴纵轴缩放比例
})
小坑
GridView做出来,会有滑动效果,根据UI的示意图和产品的要求,可能会需要添加解除滑动的容器
赞赏
如对您有帮助,支持我,不胜感激

版权声明
本文为[GuoXuan_CHN]所创,转载请带上原文链接,感谢
https://blog.csdn.net/GuoXuan_CHN/article/details/89447879
边栏推荐
- tf.keras.layers.Dense函数
- encodeURI与encodeURIComponent的区别
- nacos基础(1):什么是配置中心&Nacos介绍
- oh-my-notepro
- Carrier grade double optical port protection 8e1 + 4-way physical isolation gigabit network optical transceiver 1000m network 100m optical transceiver
- Layer1扩容:分片和可组合性
- Phthalocyanine platinum CAS: 14075-08-2 | zinc phthalocyanine ZnPc | mesoporous silicon @ upconversion @ ZnPc photosensitizer, emission below 100nm 650nm
- REINFORCE
- Goweb Foundation
- Magnesium oxide MgO crystal substrate | strontium titanate SrTiO3 crystal substrate | lithium niobate LiNbO3 crystal substrate; 10mm diameter
猜你喜欢

牛客白月赛5 【题解 数学场】

Rsync and inotify remote synchronization

BLDC双闭环(速度PI+电流PI)simulink仿真模型

nacos基础(4):配置nacos外部数据库

7-34 delete duplicate characters (set usage) & 7-35 count the number of characters (unordered_map)

使⽤airtestIDE⽣成脚本,使⽤脚本运⾏

Amino (- NH2) phthalocyanine copper CAS: 28632-30-6 (tetraaminophthalocyanine) copper (II) tetraaminophthalocyanine copper (cutapc) - shared by Qiyue biological editor

PWM output of STM32 to steering gear sg90

云计算学习1——OpenStack云计算安装部署步骤图文并茂(先电2.2)

【大话云原生】微服务篇-五星级酒店的服务方式
随机推荐
[quick link] a necessary calculation tool for Electronic Engineers - square wave circuit aided design form
nacos基础(4):配置nacos外部数据库
【优麒麟】22.04 LTS版本即将发布,终极预告来袭,你准备好了吗?
汉源高科PDH光端机双光口保护+4路E1+4路千兆网络+4路百兆网络光端机
What are the suffocating questions in the interview of computer guarantee research?
Cr doped strontium titanate Cr: SrTiO3 crystal substrate | NaCl < 111 > 10x10x2 0mm1sp crystal substrate | Al2O3 sapphire crystal substrate | Qiyue biology
Fluorescently labeled hyaluronic acid
【论文阅读】【3d目标检测】pvgnet
Golang learning, pointer, loop control, correlation
7-34 删除重复字符(set用法)&&7-35 统计字符出现次数(unordered_map)
Tita 绩效宝:管理者在绩效考核中犯的8个错误
Make the airtest ide into a script and make the script run
16 way E1 optical transceiver + 4-way 100M Ethernet optical transceiver PDH optical transceiver 2m integrated service optical transceiver
Informatics Aosai yibentong 1211: judge whether elements exist | openjudge 1.13 41: judge whether elements exist
MySQL深入学习(三二):数据库其它调优策略
Network development in WinForm
CPU的基本工作流程
PDH光端机综合多业务光接入设备双光口传16路E1 2M+4路千兆1000M网络+4路百兆共享网络机架式双电源
Should everyone use OKR?
pycharm终端pip安装Error: “pip”项识别为 cmdlet、函数、脚本文件或可运行程序的名称