注意:无特殊说明,Flutter版本及Dart版本如下: Flutter版本: 1.12.13+hotfix.5 Dart版本: 2.7.0 ReorderableListView是通过长按拖动某一项
List<String> items = List.generate(20,(int i) => '$i');
ReorderableListView(
children: <Widget>[
for (String item in items)
Container(
key: ValueKey(item),height: 100,margin: EdgeInsets.symmetric(horizontal: 50,vertical: 10),decoration: BoxDecoration(
color:
Colors.primaries[int.parse(item) % Colors.primaries.length],borderRadius: BorderRadius.circular(10)),)
],onReorder: (int oldIndex,int newIndex) {
if (oldIndex < newIndex) {
newIndex -= 1;
}
var child = items.removeAt(oldIndex);
items.insert(newIndex,child);
setState(() {});
},)
ReorderableListView(
header: Text(
'一枚有态度的程序员',style: TextStyle(color: Colors.red,fontSize: 20),)
...
)
ReorderableListView(
reverse: true,...
)
ReorderableListView(
scrollDirection: Axis.horizontal,...
)