在 app_bar.dart 文件中提到,海拔控制应用栏下方阴影的大小,并且默认情况下,如果应用栏下方没有滚动内容,则不会绘制阴影。
这是我的代码:
Scaffold(
appBar: AppBar(
brightness: Brightness.light,
backgroundColor: Colors.grey[50],
leading: IconButton(
icon: Icon(Icons.menu, color: Colors.blue),
tooltip: 'Navigation menu',
onPressed: null,
),
actions: <Widget>[
IconButton(
icon: Icon(Icons.search, color: Colors.blue,),
tooltip: 'Search',
onPressed: null,
),
],
),
body: listView,
);
Run Code Online (Sandbox Code Playgroud)
在我的情况下总是绘制阴影!有没有办法解决这个问题,或者我做错了什么?
谢谢
要删除 的高度AppBar,只需将其设置elevation为 0。如果您想在内容在 下滚动时保持高度AppBar,只需设置scrolledUnderElevation一个非零值即可。请参阅文档。
AppBar(
elevation: 0,
scrolledUnderElevation: 4,
)
Run Code Online (Sandbox Code Playgroud)
实际上,SliverAppBar 正是使用了这种当内容未滚动到其下方时没有阴影的行为,如果您愿意,它甚至可以在您滚动内容时滚动走开。以下视频解释了如何在 Flutter 应用程序中使用 slivers:https://www.youtube.com/watch?v=wN2lpqxkB4M
另外,如果您只想让 AppBar 没有阴影,您可以将其海拔属性设置为 0.0,就像这样:
AppBar(
elevation: 0.0,
title: Text("This is my title"),
),
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4344 次 |
| 最近记录: |