【问题标题】:Removing the drop shadow from a Scaffold AppBar in Flutter?从 Flutter 中的 Scaffold AppBar 中删除阴影?
【发布时间】:2018-08-07 11:25:02
【问题描述】:

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

【问题讨论】:

    标签: flutter dart shadow appbar flutter-widget


    【解决方案1】:

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

    【讨论】:

    • 对我有用。
    【解决方案2】:

    如果您想在不重复代码的情况下移除所有应用栏的阴影,只需在您的 MaterialApp 小部件内将带有 elevation: 0AppBarTheme 属性添加到您的应用主题 (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.
        )
      ),
    );
    

    【讨论】:

      【解决方案3】:

      我尝试了一些可能对你有帮助的方法

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

      看看这个

      【讨论】:

        【解决方案4】:

        要移除 appbar 下拉阴影,请设置 AppBar 构造函数 elevation: 0.0

        参数 primary、toolbarOpacity、bottomOpacity 和 automaticallyImplyLeading 不得为空。此外,如果指定了高程,则它必须为非负数。

        如果 backgroundColor、elevation、shadowColor、brightness、iconTheme、actionIconTheme、textTheme 或 centerTitle 为 null,则将使用它们的 AppBarTheme 值。如果对应的 AppBarTheme 属性为 null,则将使用属性文档中指定的默认值。

        appBar: AppBar(
           title: Text('App Title'),
           elevation: 0.0,
           bottomOpacity: 0.0,
        ),
        

        更多:AppBar constructor

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-10-30
          • 1970-01-01
          • 2023-02-05
          • 1970-01-01
          • 1970-01-01
          • 2021-11-30
          • 2010-10-11
          • 2016-08-06
          相关资源
          最近更新 更多