在 Flutter 中使用 Scaffold 小部件时,有没有办法去除应用栏(AppBar 类)下的阴影?
查看 AppBar
构造函数,有一个 elevation
属性可用于设置应用栏的高度,从而设置阴影投射量。将此设置为零将删除阴影:
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('My App Title'),
elevation: 0,
),
body: const Center(
child: Text('Hello World'),
),
);
}
https://i.stack.imgur.com/asNcQ.png
我尝试了一些可能对你有帮助的东西
AppBar(
backgroundColor: Colors.transparent,
bottomOpacity: 0.0,
elevation: 0.0,
),
看一下这个
如果您想在不重复代码的情况下移除所有应用栏的阴影,只需在您的 MaterialApp
小部件内将带有 elevation: 0
的 AppBarTheme
属性添加到您的应用主题 (ThemeData
):
// This code should be located inside your "MyApp" class, or equivalent (in main.dart by default)
return MaterialApp(
// App Theme:
theme: ThemeData(
// ••• ADD THIS: App Bar Theme: •••
appBarTheme: AppBarTheme(
elevation: 0, // This removes the shadow from all App Bars.
)
),
);