gpt4 book ai didi

dart - Flutter ReorderableListView 示例

转载 作者:行者123 更新时间:2023-12-03 04:11:53 27 4
gpt4 key购买 nike

任何人都可以展示如何制作这个吗?

enter image description here

最佳答案

您可以使用此代码。

class _HomePageState extends State<HomePage> {
List<String> _list = List.generate(5, (i) => "${i}");

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: ReorderableListView(
padding: EdgeInsets.symmetric(horizontal: 40),
children: _list.map((String string) => ListTile(key: Key(_list[_list.indexOf(string)]), title: Text(string))).toList(),
onReorder: (oldIndex, newIndex) {
String old = _list[oldIndex];
if (oldIndex > newIndex) {
for (int i = oldIndex; i > newIndex; i--) {
_list[i] = _list[i - 1];
}
_list[newIndex] = old;
} else {
for (int i = oldIndex; i < newIndex - 1; i++) {
_list[i] = _list[i + 1];
}
_list[newIndex - 1] = old;
}
setState(() {});
},
),
);
}
}

关于dart - Flutter ReorderableListView 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56238587/

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