从Flutter中的脚手架AppBar中删除阴影?

Mat*_* S. 28 flutter

有没有办法在Flutter中使用Scaffold小部件时删除应用栏(AppBar类)下的投影?

Mat*_* S. 76

查看AppBar构造函数,有一个提升属性,可用于设置应用栏的高度,从而设置阴影投射量.将此值设置为零将删除投影:

    @override
    Widget build(BuildContext context) {
        return new Scaffold(
            appBar: new AppBar(
                title: new Text('My App Title'),
                elevation: 0.0,
            ),
            body: new Center(
                child: new Text('Hello World'),
            ),
        );
    }
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


Yas*_*kar 33

我试过一些可能对你有帮助的东西

AppBar(
backgroundColor: Colors.transparent,
bottomOpacity: 0.0,
elevation: 0.0,
),
Run Code Online (Sandbox Code Playgroud)

看一下这个


Thi*_*oAM 16

如果您想在不重复代码的情况下移除所有应用栏的阴影,只需在您的小部件内为您的应用主题 ( )添加一个AppBarTheme属性:elevation: 0ThemeDataMaterialApp

// 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.
    )
  ),
);
Run Code Online (Sandbox Code Playgroud)


Ale*_*ntt 5

似乎最近的 Flutter 版本(3.3/3.7+)引入了一个名为 的新参数scrolledUnderElevation

AppBar(
  backgroundColor: Colors.transparent,
  bottomOpacity: 0.0,
  elevation: 0.0,
  // New parameter:
  scrolledUnderElevation: 0,
);
Run Code Online (Sandbox Code Playgroud)