当前位置:网站首页>Flutter | the easiest way to add header and footer to listview
Flutter | the easiest way to add header and footer to listview
2022-07-24 00:21:00 【Stars without night】
I see many people using CustomScrollView, My heart aches , How to kill a chicken ?

Take a good look at the code , A little Column Can solve the problem :
class _AddHeaderFooterListPageState extends State<AddHeaderFooterListPage> {
final _dataArray = [1, 2, 3];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: BaseAppBar(titleText: ' Add header and suffix '),
body: ListView.builder(
itemCount: _dataArray.length,
itemBuilder: (context, index) {
if (index == 0) {
// start
return Column(
children: [
_buildHeader(),
_buildCell(index),
],
);
} else if (index == _dataArray.length - 1) {
// ending
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(' This is a cell-$index'),
);
}
Widget _buildHeader() {
return Container(
alignment: Alignment.center,
height: 100,
color: Colors.red,
child: const Text(' This is the header '),
);
}
Widget _buildFooter() {
return Container(
alignment: Alignment.center,
height: 100,
color: Colors.green,
child: const Text(' This is the end of the watch '),
);
}
}
边栏推荐
- 作为一个程序员,有什么想对新人说的吗?
- The implementation in Oracle replaces the specified content of the specified column with the desired content
- Gbase 8C string operator
- 【译】Go RPC 入门:Hello World
- Mobile terminal H5 - a lifeline timeline
- IIS deployment.Netcore
- GBase 8c 会话信息函数(二)
- Redis master-slave synchronization mechanism
- Gbase 8C access authority query function (6)
- ansible命令自动补全
猜你喜欢

vulnhub wpwn: 1

paypal订阅流程及api请求

inode、软链接、硬链接

二叉搜索树的简易实现及剖析

Sum of submatrix

Docker pulls the redis image and runs it

What are blue-green deployment, Canary release and a/b test

IIS deployment.Netcore

L2TP的LAC自动拨号实验

Understanding polymorphism and letting different "people" do the same thing will produce different results
随机推荐
[Android kotlin] property, getter and setter
OA项目之我的会议(查询)
Difference between data index and label system of data warehouse
泛型机制和增强for循环
Jenkins 使用sonarqube构建流水线代码审查项目
作为一个程序员,有什么想对新人说的吗?
自己喜欢投资
Pipeline pipeline project is built by declarative and jenkinsfile under Jenkins
Redis persistence mechanism RDB, AOF
GBase 8c 会话信息函数(一)
腾讯将关闭“幻核”,数字藏品领域发展是否面临阻力?
【微信小程序】拍卖商品详情页设计与交互实现(包含倒计时、实时更新出价)
Pytest interface automated testing framework | how to get help
Gbase 8C access authority query function (6)
Comparison of the shortcomings of redis master-slave, sentinel and cluster architectures
As a programmer, is there anything you want to say to the newcomer?
Educational Codeforces Round 132 (Rated for Div. 2)(A-D)
Mobile terminal H5 - a lifeline timeline
Educational Codeforces Round 132 (Rated for Div. 2)(A-D)
mongodb的多数据源配置