flutter 为什么closeWhenOpened在可滑动文件夹上不起作用?

myzjeezk  于 2023-03-03  发布在  Flutter
关注(0)|答案(1)|浏览(152)

我想在幻灯片上使用closeWhenOpened,我把它设为true,但是我可以有多张幻灯片,我只想用一张幻灯片,但是它不起作用。
下面是我的代码,

class _mapButton extends StatelessWidget {
  const _mapButton({
    Key? key,
    required this.mapData,
  }) : super(key: key);

  final MapData mapData;

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      padding: const EdgeInsets.all(10),
      child: TCard(
        child: Container(
          width: double.infinity,
          child: SlidableAutoCloseBehavior(
            closeWhenOpened: true,
            closeWhenTapped: true,
            child: Slidable(
              closeOnScroll: false,
              endActionPane: ActionPane(
                motion: const ScrollMotion(),
                children: [
                  SlidableAction(
                    icon: Icons.delete_outline,
                    label: "삭제",
                    backgroundColor: Colors.red,
                    onPressed: (context) {
                      print(mapData.id);
                    },
                  ),
                  SlidableAction(
                    icon: Icons.delete_outline,
                    label: "수정",
                    backgroundColor: TColor.backColor,
                    onPressed: (context) {
                      print(mapData.id);
                    },
                  ),
                ],
              ),
              child: Container(
                width: double.infinity,
                child: InkWell(
                  onTap: () {
                    print("클릭");
                  },
                  child: Container(
                    padding: const EdgeInsets.all(10),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          "data",
                          style: TText.style.titleLarge,
                        ),
                        const SizedBox(height: 10),
                        Text(
                          "data",
                          style: TText.style.titleSmall,
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ),
          ),
    ),
  ),
);

}}
可滑动的

SlideableAutoCloseBehavior(
            closeWhenOpened: true,
            closeWhenTapped: true,

,但它会有2张幻灯片,你只能有一张幻灯片吗?,为什么closeWhenOpened:真的,
这不管用吗?
我使用flutter_slidable:^1.3.0,由于版本更新,我不知道用法是否发生了变化,或者我使用错误,您能给我一些建议吗?

k4ymrczo

k4ymrczo1#

我遇到了同样的问题。解决方法是将allSlidable Package 在单个SlidableAutoCloseBehavior中。将每个Slidable Package 为自己的SlidableAutoCloseBehavior只是对小部件的错误使用。
1组Slidable小工具的1个SlidableAutoCloseBehavior小工具
小部件树示例:

SlidableAutoCloseBehavior(
   child: ListView(
      children: [
        Slidable(...), 
        Slidable(...), 
        Slidable(...), 
      ],
    ), 
)

我希望这对某人有帮助。

相关问题