在 Flutter 中移除脚手架应用栏上的阴影?

在 Flutter 中使用支架小部件时,有没有办法移除应用程序栏(AppBar 类)下的阴影?

95657 次浏览

查看 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'),
),
);
}

enter image description here

If you want to remove the shadow of all app bars without repeating code, just add a AppBarTheme property with elevation: 0 to your app theme (ThemeData), inside your MaterialApp widget:

// 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.
)
),
);

我试过一些方法,可能会对你有帮助

AppBar(
backgroundColor: Colors.transparent,
bottomOpacity: 0.0,
elevation: 0.0,
),

看看这个