简体   繁体   English

如何删除 ReorderableListView - flutter 底部的多余间距?

[英]How to Remove extra spacing at the bottom of ReorderableListView - flutter?

I'm trying to create a ReorderableListView in a flutter with dynamic data.我正在尝试使用动态数据在 flutter 中创建一个 ReorderableListView。 Extra spacing coming at the bottom of the list.额外的间距出现在列表的底部。 Any help would be appreciated.任何帮助,将不胜感激。

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,
            border: Border.all(color: Colors.white,width: 2),
            borderRadius: BorderRadius.all(Radius.circular(4))
          ),

          child: Padding(
            padding: const EdgeInsets.all(8.0),
            child: Text(_item+" Items",textAlign: TextAlign.start,
            style: TextStyle(color: Colors.black54,fontSize: 18),),
          ),
        ),
      ),
    );
   }

  _updateMyItems(int old,int newIndex)
  {
    setState(() {

      if(newIndex>old)
        {
          newIndex-=1;
        }
        var item=_listData.removeAt(old);
      _listData.insert(newIndex, item);


    });

  }
}

The Extra space of 100px is added intentionally to allow List item to be added to that space while dragging.特意添加了 100px 的额外空间,以允许在拖动时将列表项添加到该空间。

You can see the source Here at github您可以在 github看到源代码

static const double _defaultDropAreaExtent = 100.0;

The only solution is to use any other custom made ReorderListView Libraries and plugins.唯一的解决方案是使用任何其他定制的 ReorderListView 库和插件。 Or You can copy this file (perks of open source) and make changes according to your requirement.或者您可以复制此文件(开源特权)并根据您的要求进行更改。

For instance, you can change the same value to drop the extra spacing but it would make a user to wait for the animated item to complete there animation & reordering and then he/she will be able to drop that item in that place (at end).例如,您可以更改相同的值以删除额外的间距,但这会使用户等待动画项目在那里完成 animation 并重新排序,然后他/她将能够将该项目放在那个地方(最后)。

I believe you can use MediaQuery.removePadding :我相信您可以使用MediaQuery.removePadding

MediaQuery.removePadding(
            context: context,
            removeBottom: true,
            child: Text("Your child here")
           )

Which allows you to remove default padding applied in some cases这允许您删除在某些情况下应用的默认填充

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM