繁体   English   中英

是否可以在flutter中为SliverList内的按钮实现一个可禁用的窗口小部件

[英]is it Possible to Implement a Dismissible widget for a button inside a SliverList in flutter

所以我要说我已经建立了一个看起来像这样的条子清单。

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

可滑动列表项的Flutter实现,其中包含可以解除的方向滑动操作。

用法:

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

    );

暂无
暂无

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

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