当前位置:网站首页>Flutter | 给 ListView 添加表头表尾最简单的方式
Flutter | 给 ListView 添加表头表尾最简单的方式
2022-07-23 12:08:00 【无夜之星辰】
看到有不少人在用 CustomScrollView,我实在心痛,杀鸡焉用牛刀?

好好看代码,一个小小的 Column 就能解决问题:
class _AddHeaderFooterListPageState extends State<AddHeaderFooterListPage> {
final _dataArray = [1, 2, 3];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: BaseAppBar(titleText: '添加表头表尾'),
body: ListView.builder(
itemCount: _dataArray.length,
itemBuilder: (context, index) {
if (index == 0) {
// 开头
return Column(
children: [
_buildHeader(),
_buildCell(index),
],
);
} else if (index == _dataArray.length - 1) {
// 结尾
return Column(
children: [
_buildCell(index),
_buildFooter(),
],
);
} else {
return _buildCell(index);
}
},
),
);
}
Widget _buildCell(int index) {
return Container(
alignment: Alignment.centerLeft,
height: 30,
color: Colors.orange,
child: Text('这是cell-$index'),
);
}
Widget _buildHeader() {
return Container(
alignment: Alignment.center,
height: 100,
color: Colors.red,
child: const Text('这是表头'),
);
}
Widget _buildFooter() {
return Container(
alignment: Alignment.center,
height: 100,
color: Colors.green,
child: const Text('这是表尾'),
);
}
}
边栏推荐
- Bean validation core components - 04
- Translucenttb recommendations
- Basic concept and deployment of kubernetes
- [operation and maintenance] SSH tunneling relies on the 22 port of SSH to realize the interface service of accessing the remote server
- Without Huawei, Qualcomm will raise prices at will, and domestic mobile phones that lack core technology can only be slaughtered
- 激光共聚焦如何选择荧光染料
- 关于初始化page入参的设计思路
- 黑马程序员-接口测试-四天学习接口测试-第三天-postman高级用法,newman例集导出导入,常用断言,断言json数据,工作原理,全局,环境变量,时间戳,请求前置脚本,关联,批量执行测试用例
- EmguCV录制视频
- 2022蓝帽杯初赛wp
猜你喜欢

After Effects 教程,如何在 After Effects 中创建动画?

SOC的第一个Hello_World实验

Google Earth engine -- null value problem in image statistics

Bean Validation核心组件篇----04

Cloud native (11) | kubernetes chapter kubernetes principle and installation

JSP之自定义jstl标签

2022 blue hat cup preliminary WP

Bean Validation核心組件篇----04

关于初始化page入参的设计思路

Mysql客户端到服务端字符集的转换
随机推荐
Ora-01654 error: table space is full, insert failed
2022蓝帽杯初赛wp
Bean validation specification ----03
Bean Validation规范篇----03
Three handling strategies of deadlock
[SUCTF 2018]MultiSQL(mysql预编译)
[attack and defense world web] difficulty Samsung 9-point introductory question (middle): ics-05, easytornado
TranslucentTB 推荐
JSP之自定义jstl标签
MySQL - six logs
Esp8266 nodemcu flash file system (spiffs)
Packaging and use of alamofire framework
js过滤/替换敏感字符
Design idea of initializing page input parameters
MySQL soul 16 ask, how many questions can you hold on to?
Middle aged crisis, retired at the age of 35, what do migrant workers take to compete with capitalists?
FMDB的封装与使用
(Zset) how is the underlying layer of redis stored with a hop table
Alamofire 框架封装与使用
Packaging and use of fmdb