我正在使用带有SliverChildBuilderDelegate的SliverList来动态生成列表项。现在,我正在尝试允许用户通过拖放在一行中的每个项目上的句柄图标上重新排序列表项目。
我尝试过不同的东西(比如可拖放的Widget),但到目前为止我还没有找到解决方案。是否有人已经使用过SliverList Widget的拖放重新排序,并能给我一个提示?
使用ReorderableListView Widget是不可能的,导致将ListView与SliverList混合。我想使用SliverAppBar来允许渐变滚动效果,如您在这里看到的:https://medium.com/flutter-io/slivers-demystified-6ff68ab0296f。
这里是我的SliverList:的结构
return Scaffold(
body: RefreshIndicator(
...
child: CustomScrollView(
...
slivers: <Widget>[
SliverAppBar(...),
SliverList(
delegate: SliverChildBuilderDelegate(...),
)
...
提前谢谢,迈克尔
发布于 2019-03-05 07:12:32
看看这个酒吧里的再订购品包。它最近增加了对SliverList的支持。
该示例有条条列表和应用程序栏,并显示了您正在寻找的内容。只需将代码中的SliverList和SliverChildBuilderDelegate替换为包中的计数器部件即可。
class _SliverExampleState extends State<SliverExample> {
List<Widget> _rows;
@override
void initState() {
super.initState();
_rows = List<Widget>.generate(50,
(int index) => Text('This is sliver child $index', textScaleFactor: 2)
);
}
@override
Widget build(BuildContext context) {
void _onReorder(int oldIndex, int newIndex) {
setState(() {
Widget row = _rows.removeAt(oldIndex);
_rows.insert(newIndex, row);
});
}
ScrollController _scrollController = PrimaryScrollController.of(context) ?? ScrollController();
return CustomScrollView(
// a ScrollController must be included in CustomScrollView, otherwise
// ReorderableSliverList wouldn't work
controller: _scrollController,
slivers: <Widget>[
SliverAppBar(
expandedHeight: 210.0,
flexibleSpace: FlexibleSpaceBar(
title: Text('ReorderableSliverList'),
background: Image.network(
'https://upload.wikimedia.org/wikipedia/commons/thumb/6/68/Yushan'
'_main_east_peak%2BHuang_Chung_Yu%E9%BB%83%E4%B8%AD%E4%BD%91%2B'
'9030.png/640px-Yushan_main_east_peak%2BHuang_Chung_Yu%E9%BB%83'
'%E4%B8%AD%E4%BD%91%2B9030.png'),
),
),
ReorderableSliverList(
delegate: ReorderableSliverChildListDelegate(_rows),
// or use ReorderableSliverChildBuilderDelegate if needed
// delegate: ReorderableSliverChildBuilderDelegate(
// (BuildContext context, int index) => _rows[index],
// childCount: _rows.length
// ),
onReorder: _onReorder,
)
],
);
}
}
发布于 2019-01-10 03:27:23
发布于 2022-09-20 10:20:32
现在可以从正式的颤振小部件库中使用SliverReorderableList
。
https://stackoverflow.com/questions/53980410
复制相似问题