Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 是否可以在flift中为SliverList中的按钮实现一个可拒绝的小部件_Android_Dart_Flutter - Fatal编程技术网

Android 是否可以在flift中为SliverList中的按钮实现一个可拒绝的小部件

Android 是否可以在flift中为SliverList中的按钮实现一个可拒绝的小部件,android,dart,flutter,Android,Dart,Flutter,假设我建立了一个类似这样的sliverlist return new Container( child: new CustomScrollView( scrollDirection: Axis.vertical, shrinkWrap: false, slivers: <Widget>[ new SliverPadding(

假设我建立了一个类似这样的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),
                ),
              ),
            ],
          ));
现在我想有一个图标按钮来关闭一个项目,所以我把它添加到卡里面

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

您将如何在图标按钮中实现dismissible小部件,当在Flatter中按下该按钮时,该按钮将关闭列表中的项目?

好的,已经有一个包可以满足您的需要

具有方向滑动的可滑动列表项的颤振实现 可以驳回的行动

用法:

  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'),
      ),
    ],

    );
newslideable(
委托:新的SlideableScrollDelegate(),
行动延伸率:0.25,
子容器:新容器(
颜色:颜色,白色,
孩子:新的ListTile(
领先:新CircleAvatar(
背景颜色:Colors.indigoAccent,
子项:新文本(“$3”),
前底色:颜色。白色,
),
标题:新文本('Tile n°$3'),
副标题:新文本(“SlideableDrawerDelegate”),
),
),
行动:[
新IconSlideAction(
标题:"档案",,
颜色:颜色,蓝色,
图标:Icons.archive,
onTap:()=>\u showSnackBar('Archive'),
),
新IconSlideAction(
描述:“共享”,
颜色:颜色,靛蓝,
图标:Icons.share,
onTap:()=>\u showSnackBar('Share'),
),
],
);

您按下按钮时是否需要删除该项?哦,是的,我忘了提及,我的朋友。您能描述一下您当前实现中存在的问题吗?我可以在文档中给出的常见示例和某些站点中的一些示例中使用dismissible widget,但我似乎找不到在列表视图中使用按钮或图标按钮来关闭项目而不是使用Dismissible的例子,如果您只是滑动它来删除它,为什么不使用Dismissible?我认为Dismissible没有选择在小部件消失之前滑动它时的操作。
  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'),
      ),
    ],

    );