gpt4 book ai didi

flutter - 如何在 flutter 中将页脚添加到 ReorderableListView

转载 作者:行者123 更新时间:2023-12-03 13:29:18 25 4
gpt4 key购买 nike

尝试使用 制作包含页眉和页脚的 ui可重新排列的内容 项目。有一个属性叫 标题我们可以从中添加标题项。但是如果我想添加怎么办页脚项目也是如此。

import 'package:flutter/material.dart';

class MyStickyHeader extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _MyStickyHeaderState();
}
}

class _MyStickyHeaderState extends State<MyStickyHeader> {
List<Widget> _list = [
Text("Apple"),
Text("Ball"),
Text("Cat"),
Text("Dog"),
Text("Elephant")
];

@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.only(top: 30, left: 10),
color: Colors.white,
child: showData(),
);
}

Widget showData() {
return Container(
child: ReorderableListView(
header: Container(
height: 100,
color: Colors.red,
),
children: _list
.map((item) => Container(
padding: EdgeInsets.all(10),
key: Key("${(item as Text).data}"),
child: Row(
children: <Widget>[
Icon(Icons.ac_unit),
Expanded(
child: item,
)
],
),
))
.toList(),
onReorder: (int start, int current) {
// dragging from top to bottom
if (start < current) {
int end = current - 1;
Widget startItem = _list[start];
int i = 0;
int local = start;
do {
_list[local] = _list[++local];
i++;
} while (i < end - start);
_list[end] = startItem;
}

// dragging from bottom to top
if (start > current) {
Widget startItem = _list[start];
for (int i = start; i > current; i--) {
_list[i] = _list[i - 1];
}
_list[current] = startItem;
}
setState(() {});
},
),
);
}
}

最佳答案

列表的最后一个元素可以是页脚。它必须是具有 onLongPress 属性的小部件。例如:

ReorderableListView(
onReorder: (int oldIndex, int newIndex) {},
children: List.generate(someList.items.length + 1, (index) {
if (index < someList.items.length)
return ListTile(
key: Key(someList.items[index].description),
);
else
return RaisedButton(key: Key('footer'), onPressed: () {}, onLongPress: (){}, child: Text('Button'));
})),

关于flutter - 如何在 flutter 中将页脚添加到 ReorderableListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56815976/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com