Flutter elevation 属性导致的颜色变更
创建一个 BottomShee
里面包含了一个 AppBar
组件,发现 AppBar
与 BottomSheet
主体存在颜色差距:
showModalBottomSheet(
context: context,
builder: (context) {
return Column(children: [
AppBar(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(28.0)),
),
)
]);
},
);
刚开始我准备改变 AppBar
的 backupColor
属性,认为只是把颜色调整为 BottomSheet
的默认颜色就 ok 了。但是奇怪的是 Theme.of(context)
里的颜色试了一个遍也没找到这个颜色,我都傻了🥲。
后面才发现是 BottomSheet
里的 elevation
属性默认设置为了 1.0,才产生了这个颜色。把 AppBar
的 elevation
也设置为 1.0 就可以了。
showModalBottomSheet(
context: context,
builder: (context) {
return Column(children: [
AppBar(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(28.0)),
),
elevation: 1.0,
)
]);
},
);