抽屉小部件打开时如何修改背景的淡入淡出效果?
How to modify fade effect of background when Drawer widget is opened?
我有一个黑色背景的脚手架,它有一个也是黑色的抽屉。由于打开抽屉时发生的淡入淡出效果是淡入 'Colors.black54'(黑色,不透明度为 54%),所以抽屉的边框不可见。
我希望它褪色为灰色,不透明度为 54%。
我发现唯一可以做到这一点的方法是直接修改 Flutter 的源代码文件 "drawer.dart"(第 382 行),但这不是实际的解决方案,更像是一种 hack。
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
)
)
),
),
),
);
当你拿出抽屉时,我会让 Scaffold 的 backgroundColor 动画为 white/gray。
AnimatedController(
builder: (...) {
Color col = Color.lerp(
Colors.white,
Colors.black,
Curves.someCurve.transform(controller.value);
return Scaffold(
key: _key,
backgroundColor: col,
drawer: ...
);
}
我在 Github 上提出了一个问题并得到了这个答案,它为你完成了所有工作(但在 flutter 的稳定频道中还不存在,仅在 1.6.0 及更高版本上存在) .
"If you're using Flutter v1.6.0 and above, you can pass the drawerScrimColor to your Scaffold. This was added recently in #31025. See more about using a higher Flutter version in the docs about Flutter's channels."
https://github.com/flutter/flutter/issues/34171#issuecomment-500590613
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
)
)
),
),
),
);
我有一个黑色背景的脚手架,它有一个也是黑色的抽屉。由于打开抽屉时发生的淡入淡出效果是淡入 'Colors.black54'(黑色,不透明度为 54%),所以抽屉的边框不可见。
我希望它褪色为灰色,不透明度为 54%。
我发现唯一可以做到这一点的方法是直接修改 Flutter 的源代码文件 "drawer.dart"(第 382 行),但这不是实际的解决方案,更像是一种 hack。
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
)
)
),
),
),
);
当你拿出抽屉时,我会让 Scaffold 的 backgroundColor 动画为 white/gray。
AnimatedController(
builder: (...) {
Color col = Color.lerp(
Colors.white,
Colors.black,
Curves.someCurve.transform(controller.value);
return Scaffold(
key: _key,
backgroundColor: col,
drawer: ...
);
}
我在 Github 上提出了一个问题并得到了这个答案,它为你完成了所有工作(但在 flutter 的稳定频道中还不存在,仅在 1.6.0 及更高版本上存在) .
"If you're using Flutter v1.6.0 and above, you can pass the drawerScrimColor to your Scaffold. This was added recently in #31025. See more about using a higher Flutter version in the docs about Flutter's channels."
https://github.com/flutter/flutter/issues/34171#issuecomment-500590613
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
)
)
),
),
),
);