简体   繁体   English

在 flutter 的应用栏顶部添加阴影

[英]adding a shadow to the top of an appbar in flutter

I'm struggling to add a shadow to the top of the AppBar, I have added one to the bottom but not the top.我正在努力在 AppBar 的顶部添加阴影,我在底部添加了一个,但没有在顶部添加。 Here's the design I'm trying to match:这是我要匹配的设计:

设计

I've explicitly defined the system status bar details in AppBarTheme as white:我已将 AppBarTheme 中的系统状态栏详细信息明确定义为白色:

    systemOverlayStyle: SystemUiOverlayStyle(
      statusBarIconBrightness: Brightness.dark,
      statusBarBrightness: Brightness.dark,
      statusBarColor: Colors.white.withOpacity(0.0)),

and I've pushed the entire scaffold into the SafeArea:我已将整个脚手架推入 SafeArea:

  Widget build(BuildContext context) => GestureDetector(
    onTap: () => FocusScope.of(context).unfocus(),
    child: SafeArea(
      child: Scaffold(
        appBar: PreferredSize(
          preferredSize: Size.fromHeight(256),
          child: Container( // extra container for custom bottom shadows
            decoration: BoxDecoration(
              boxShadow: [
                BoxShadow(
                  color: Colors.black.withOpacity(0.5),
                  spreadRadius: 6,
                  blurRadius: 6,
                  offset: Offset(0, -4),
                ),
              ],
            ),
            child: AppBar(...),
          ),
        ),
        ...
      ),
    ),
  );
  }

plus, by the way I added a rounded edge on top so I could see what was going on:另外,顺便说一下,我在顶部添加了一个圆边,这样我就可以看到发生了什么:

执行

Notice, a shadow is present, but is underneath the status bar.请注意,阴影存在,但位于状态栏下方。 So I guess what I'm struggling to achieve is putting the statusbar behind the appbar... or at least making it look that way (with like a mirrored shadow on top of the status bar or something?)所以我想我正在努力实现的是将状态栏放在应用栏后面......或者至少让它看起来像那样(在状态栏顶部有一个镜像阴影或其他东西?)

How would you go about solving this?你会如何解决这个问题? is there like a StatusBarTheme or something for this purpose?是否有类似 StatusBarTheme 或用于此目的的东西?

Please Refer below code.
Add elevation and Check. 

 Scaffold(
                            backgroundColor: Colors.white,
                            
                            appBar: AppBar(
                              elevation: 5.0,
                             backgroundColor: Colors.white,
                              actions: [

                            ],)
                          ),

I had to use stack:我不得不使用堆栈:

    SafeArea(
      child: Stack(children: [
        Container(
            decoration: BoxDecoration(
                borderRadius: BorderRadius.only(
                    bottomRight: Radius.circular(8.0),
                    bottomLeft: Radius.circular(8.0)),
                color: const Color(0xffffffff),
                boxShadow: [
              BoxShadow(
                  color: const Color(0x33000000),
                  offset: Offset(0, 2),
                  blurRadius: 4),
            ])),
        AppBar(...
        ...

without any systemOverlayStyle specifications in the Theme.主题中没有任何 systemOverlayStyle 规范。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM