微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android-是否有可能在Flutter中为SliverList中的按钮实现Dismissible小部件

所以可以说我建立了一个像这样的sliverlist.

return new Container(
              child: new CustomScrollView(
            scrollDirection: Axis.vertical,
            shrinkWrap: false,

            slivers: <Widget>[
              new SliverPadding(
                padding: const EdgeInsets.symmetric(vertical: 2.0),
                sliver: new SliverList(
                  delegate: new SliverChildBuilderDelegate(
                      (BuildContext context, int index) {
                    ModelClass class= _List[index];

                    return new dismissible(
                      key: new ObjectKey(_List[index]),
                      child: ModelCard(class),
                      ondismissed: (dismissDirection direction) {
                        setState(() {
                          _List.removeAt(index);

                          direction == dismissDirection.endToStart;
                        });
                      },
                      background: new Container(
                          color: const Color.fromrGBO(183, 28, 28, 0.8),
                          child: new Center(
                            child: new Text(
                              "Item Removed",
                              style: new TextStyle(color: Colors.white),
                            ),
                          )),

                    );

                    // return new ModelCard(class);
                  }, childCount: _List.length),
                ),
              ),
            ],
          ));

现在我有一个名为ModelCard的无状态小部件,可以像这样填充列表

   new Container(
                    padding: EdgeInsets.fromLTRB(80.0, 10.0, 0.0, 0.0),
                    child: new Text(
                      "${class.listDescription}",
                      style: new TextStyle(),
                    ),
                  ),

现在我想有一个图标按钮来关闭一个项目,所以我将其添加到卡中

new Container(
                    padding: EdgeInsets.fromLTRB(350.0, 20.0, 0.0, 0.0),
                    child: new IconButton(
                        icon: new Icon(Icons.delete), onpressed: () {}),
                  ),

您如何在按下图标时在可弹出的菜单按钮中实现可消除的窗口小部件呢?

解决方法:

好的,已经有一个可以满足您需求的软件包.

https://pub.dartlang.org/packages/flutter_slidable

A Flutter implementation of slidable list item with directional slide
actions that can be dismissed.

用法

  new Slidable(
    delegate: new SlidableScrollDelegate(),
    actionExtentRatio: 0.25,
    child: new Container(
      color: Colors.white,
      child: new ListTile(
        leading: new CircleAvatar(
          backgroundColor: Colors.indigoAccent,
          child: new Text('$3'),
          foregroundColor: Colors.white,
        ),
        title: new Text('Tile n°$3'),
        subtitle: new Text('SlidableDrawerDelegate'),
      ),
    ),
    actions: <Widget>[
      new IconSlideAction(
        caption: 'Archive',
        color: Colors.blue,
        icon: Icons.archive,
        onTap: () => _showSnackBar('Archive'),
      ),
      new IconSlideAction(
        caption: 'Share',
        color: Colors.indigo,
        icon: Icons.share,
        onTap: () => _showSnackBar('Share'),
      ),
    ],

    );

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐