我正在尝试用动态数据创建一个ReorderableListView。额外的间隔位于列表的底部。任何帮助将不胜感激。
class _MyHomePageState extends State {
List<String> _listData = ["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15"];
@override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,backgroundColor: Colors.lightGreen,appBar: AppBar(
title: Text("Listview Drag and Drop"),backgroundColor: Colors.deepOrange,),body: Center(
child: ReorderableListView(
header:
Container(
margin: EdgeInsets.only(top: 10),decoration: BoxDecoration(
color: Colors.deepPurple,border: Border.all(color: Colors.white,width: 2),borderRadius: BorderRadius.all(Radius.circular(4))
),child: Padding(
padding: const EdgeInsets.all(8.0),child: Text("ReorderableListView",textAlign: TextAlign.start,style: TextStyle(color: Colors.white,fontSize: 18),children: [
for(final item in _listData) getchildItems(item,context)
],onReorder: (oldIndex,newIndex){
_updateMyItems(oldIndex,newIndex);
}
),);
}
getchildItems(_item,_context) {
return Padding(
key: ValueKey(_item),padding: const EdgeInsets.all(8.0),child: InkWell(
onTap: (){},child: Container(
width: double.infinity,decoration: BoxDecoration(
color: Colors.white,borderRadius: BorderRadius.all(Radius.circular(4))
),child: Padding(
padding: const EdgeInsets.all(8.0),child: Text(_item+" Items",style: TextStyle(color: Colors.black54,);
}
_updateMyItems(int old,int newIndex)
{
setState(() {
if(newIndex>old)
{
newIndex-=1;
}
var item=_listData.removeAt(old);
_listData.insert(newIndex,item);
});
}
}