Flutter AppBar高度改变背景颜色如何在显示阴影的同时保持背景?

问题描述 投票:0回答:1

问题描述:

我正在开发 Flutter 应用程序,我想使用

AppBar
elevation
属性向
shadowColor
添加阴影。然而,当我设置这些时,
AppBar
的背景颜色似乎略有变化,即使我已明确将
backgroundColor
设置为
Colors.white

滚动行为工作正常,并且滚动页面时显示正确的背景颜色。但是当应用

elevation
shadowColor
时,背景颜色看起来不同。


我尝试过的

这是我用于我的

AppBar
的代码:

AppBar(
  backgroundColor: Colors.white,
  scrolledUnderElevation: 0,
  elevation: 1.0,
  shadowColor: const Color.fromRGBO(0, 0, 0, 0.25),
)

尽管将

backgroundColor
设置为
Colors.white
,但在应用高程和阴影时,背景看起来会稍微偏离。


预期和实际结果

  • 预期
    AppBar
    在显示阴影时应保持白色背景。
  • 实际:添加阴影后,
    AppBar
    的背景颜色略有变化。

具体问题

如何确保

AppBar
保持其背景颜色(纯白色),同时仍显示
elevation
shadowColor
的阴影效果?


flutter shadow appbar elevation
1个回答
0
投票

surfaceTintColor
设置为
Colors.transparent

AppBar(
  backgroundColor: Colors.white,
  scrolledUnderElevation: 0,
  elevation: 1.0,
  shadowColor: const Color.fromRGBO(0, 0, 0, 0.25),
  surfaceTintColor: Colors.transparent,
)
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.