class Demo extends StatefulWidget { @override _DemoState createState() => _DemoState(); } class _DemoState extends State<Demo> { List<int> list = []; @override void initState() { super.initState(); for (int i = 0; i < 100; i++) { list.add(i); } } @override Widget build(BuildContext context) { return ReorderableListView( children: list.map(f).toList(), header: Text('This is the header!'), onReorder: (oldIndex, newIndex) { setState(() { _updateMyItems(oldIndex, newIndex); }); }); } void _updateMyItems(int oldIndex, int newIndex) { var tmp = list[oldIndex]; list[oldIndex] = list[newIndex]; list[newIndex] = tmp; } Widget f(int i) { return ListTile( key: ValueKey("$i"), title: Text('Item $i'), ); } }
徐兄的博客:flutterall.com
本博客所有文章如无特别注明均为原创。作者:flutter教程网 ,复制或转载请以超链接形式注明转自 Flutter教程网 。
原文地址《神奇的Flutter ReorderableListView重新排序》
原文地址《神奇的Flutter ReorderableListView重新排序》
发表评论