如何在flutter中添加Dismissible图标?

问题描述 投票:0回答:1

问你一个小问题..

在我的可关闭小部件中的这张图片中,当我将其向右或向左拖动时,它将删除我的列表中的项目。但仅仅“删除”这个词对我来说还不够,我也想成为我的文本旁边的垃圾图标......

那我该怎么办?

请帮助我。

enter image description here

我认为不必要,但我的代码:

return Dismissible(
                      key: UniqueKey(),
                      background: Container(
                        alignment: Alignment.center,
                        color: Colors.redAccent,
                        child: const Text(
                          'Delete',
                          style: TextStyle(
                            color: Colors.white,
                          ),
                          textAlign: TextAlign.center,
                        ),
                      ),
                      onDismissed: (direction) async {
                        await deletePost(listpost![index].id.toString());
                        setState(() {
                          listpost!.removeAt(index);
                          fetchAllPosts().then((value) => listpost = value);
                        });
                      },
android flutter dart user-interface dismissible
1个回答
0
投票

每当您想要两个水平放置的小部件时,您可以使用 Row 小部件 - 它接受多个子部件:

return Dismissible(
  key: UniqueKey(),
  background: Container(
    alignment: Alignment.center,
    color: Colors.redAccent,
    child: Row( // Wrap with a row here
      mainAxisAlignment: MainAxisAlignment.center,
      children: const [
        Icon(
          Icons.delete,
          color: Colors.white,
        ),
       
        Text(
          'Delete',
          style: TextStyle(
            color: Colors.white,
          ),
        ),
      ],
    ),
  ),
  onDismissed: (direction) async {
    await deletePost(listpost![index].id.toString());
    setState(() {
      listpost!.removeAt(index);
      fetchAllPosts().then((value) => listpost = value);
    });
  },
);
© www.soinside.com 2019 - 2024. All rights reserved.