Flutter-如何为状态背彩设置梯度(使用SafeArea)?
是否可以明确设置状态栏的梯度颜色? “状态巴尔科勒”期望颜色,但是渐变呢?如何在梯度中绘制状态栏?如果我使用SafeArea,则状态栏为白色。但是我的sliverappbar涂有梯度颜色。
Scaffold(
body: SafeArea(
child: CustomScrollView(
slivers: [
SliverAppBar(
flexibleSpace: FlexibleSpaceBar(
centerTitle: true,
title: Text(
'My App',
style: TextStyle(
fontSize: 16.0,
),
),
background: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: <Color>[
Color(0xFF50AC5B),
Color(0xFF92C156),
],
),
),
),
),
elevation: 0.0,
floating: true,
),
SliverList(
delegate: SliverChildListDelegate(
[
//...
],
),
),
],
),
),
backgroundColor: const Color(0xFFFBFDFF),
);
}
}
Is it possible to explicitly set gradient color for the status bar? 'statusBarColor' expects Color, but what about gradient? How to paint status bar in gradient? If I use SafeArea, status bar is white. But my SliverAppBar is painted in gradient color.
Scaffold(
body: SafeArea(
child: CustomScrollView(
slivers: [
SliverAppBar(
flexibleSpace: FlexibleSpaceBar(
centerTitle: true,
title: Text(
'My App',
style: TextStyle(
fontSize: 16.0,
),
),
background: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: <Color>[
Color(0xFF50AC5B),
Color(0xFF92C156),
],
),
),
),
),
elevation: 0.0,
floating: true,
),
SliverList(
delegate: SliverChildListDelegate(
[
//...
],
),
),
],
),
),
backgroundColor: const Color(0xFFFBFDFF),
);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下工作和测试代码:
说明:
我们如何获得这个红色阴影状态栏?
我们已经用脚手架包裹了Safearea小部件。在身体属性中,我们使用具有梯度颜色的容器,因此它占据了整个屏幕...如果我们没有Appbar的身体,则将整个屏幕作为一个主体。然后,我们可以使用其他一些小部件(根据我们的要求)
Below worked and tested code :
Explanation :
How we get this red shaded status bar?
We have wrapped SafeArea widget by scaffold. In body property we have using container with gradient color so it occupies whole screen...If we use body without appbar it takes whole screen as a body. then we can use remaining body spaces by some other Widgets(as per our requirement)
则将Safearea包裹到一个添加背景梯度的容器中
如果不需要,
,或者在应用程序的顶部关闭Safearea,例如这样:让我知道任何解决方案是否有效。
Wrap your SafeArea into a Container that adds a background gradient
or just turn off your SafeArea in the top portion of the app if it's not required there, like this:
Let me know if any of this solution works.