OpenContainer是否显示背景?

时间:2020-05-28 18:29:14

标签: flutter

我正在使用openContainer动画化FAB到视图/屏幕的过渡-但是,工厂周围似乎有一个盒子。我该如何删除呢?

OpenContainer(

          transitionDuration: Duration(milliseconds: 1000),
          closedBuilder: (BuildContext c, VoidCallback action) =>
              FloatingActionButton(
            elevation: 10,
            backgroundColor: Colors.pink,

            onPressed: () {

              action();
            },
            child: Icon(Icons.add),
          ),
          openBuilder: (BuildContext c, VoidCallback action) {
            return MyScreen();
          },
          tappable: false,
        ));

enter image description here

1 个答案:

答案 0 :(得分:2)

我遇到了同样的问题并找到了解决方案。这是删除框的替代方法-从动画github存储库中的example之后:

  1. 用包含高度和宽度的SizedBox替换FloatingActionButton
  2. 在OpenContainer中包括closedElevation属性,以保持高程效果
  3. 在OpenContainer中包括closedShape属性以使SizedBox变圆
OpenContainer(
  transitionDuration: Duration(milliseconds: 1000),
  closedColor: Colors.pink,
  closedBuilder: (BuildContext c, VoidCallback action){
    return SizedBox(
      height: 56,
      width: 56,
      child: Center(
        child: Icon(
          Icons.add,
          color: Colors.white,
        ),
      ),
    );
  }
  openBuilder: (BuildContext c, VoidCallback action) {
    return MyScreen();
  },
  tappable: false,
  closedElevation: 6.0,
  closedShape: const RoundedRectangleBorder(
    borderRadius: BorderRadius.all(
      Radius.circular(56 / 2),
    ),
  ),
);