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
Flutter 当抽屉小部件打开时,如何修改背景的淡入淡出效果?_Flutter_Dart_Drawer - Fatal编程技术网

Flutter 当抽屉小部件打开时,如何修改背景的淡入淡出效果?

Flutter 当抽屉小部件打开时,如何修改背景的淡入淡出效果?,flutter,dart,drawer,Flutter,Dart,Drawer,我有一个黑色背景的脚手架,还有一个同样是黑色的抽屉。由于抽屉打开时发生的淡入淡出效果是淡入“Colors.black54”(黑色,不透明度54%),因此抽屉的边框不可见 我希望它淡入灰色,不透明度54% 我发现唯一可以做到这一点的方法是直接修改颤振的源代码文件“drawer.dart”(第382行),但这不是一个实际的解决方案,它更像是一个黑客 return new Scaffold( backgroundColor: Colors.black, drawer: new Drawer(

我有一个黑色背景的脚手架,还有一个同样是黑色的抽屉。由于抽屉打开时发生的淡入淡出效果是淡入“Colors.black54”(黑色,不透明度54%),因此抽屉的边框不可见

我希望它淡入灰色,不透明度54%

我发现唯一可以做到这一点的方法是直接修改颤振的源代码文件“drawer.dart”(第382行),但这不是一个实际的解决方案,它更像是一个黑客

return new Scaffold(
  backgroundColor: Colors.black,
  drawer: new Drawer(
    child: new Container(
      color: Colors.black,
      child: new Center(
        child: new Text(
          'Test',
          style: new TextStyle(
            color: Colors.white
          )
        )
      ),
    ),
  ),
);

当你拿出抽屉时,我会将脚手架的背景色设置为白色/灰色

AnimatedController(
  builder: (...) {
    Color col = Color.lerp(
      Colors.white,
      Colors.black,
      Curves.someCurve.transform(controller.value);
    return Scaffold(
      key: _key,
      backgroundColor: col,
      drawer: ...
    );
  }

我在Github上提出了一个问题,得到了这个答案,它为您做了所有的工作(但在Flatter的稳定通道上还不存在,仅在版本1.6.0及以上)

“如果您使用的是Flatter v1.6.0及更高版本,则可以将DrumerscrimColor传递到脚手架。这是最近在#31025中添加的。有关使用更高版本的Flatter的详细信息,请参阅关于Flatter通道的文档。”


嘿,这是一个很好的替代方案,可能是目前在颤振的稳定通道上执行此操作的最佳方式,但是在颤振1.6.0及更高版本上,他们向Scaffold添加了一个参数,为您完成所有工作:)
return new Scaffold(
  backgroundColor: Colors.black,
  drawerScrimColor: Colors.grey.withOpacity(0.54),
  drawer: new Drawer(
    child: new Container(
      color: Colors.black,
      child: new Center(
        child: new Text(
          'Test',
          style: new TextStyle(
            color: Colors.white
          )
        )
      ),
    ),
  ),
);