簡體   English   中英

如何刪除 Flutter 中 Android 的 AppBar 上方的陰影?

[英]How can I remove shadow above AppBar for Android in Flutter?

如何刪除 Flutter 中 Android 的 AppBar 上方的陰影? 在 iOS 模擬器上,以下代碼可以正常工作。

在此處輸入圖像描述

代碼:

    return Scaffold(
        extendBodyBehindAppBar: true,
        appBar: AppBar(
          backgroundColor: Colors.transparent,
          shadowColor: Colors.transparent,
          elevation: 0.0,
          title: Text('Title'),
        ),
        body: Container(
          decoration: BoxDecoration(
            image: DecorationImage(
              image: AssetImage('images/background_01.jpg'),
              fit: BoxFit.cover,
            ),
          ),
          child: SafeArea(
            child: Column(
              children: [
                Container(),
                Container(),
              ],
            ),
          ),
        ));

將此添加到小部件

Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
  statusBarColor: Colors.transparent,
));
return Scaffold(

它的狀態欄嘗試更改狀態欄

將您的安全區域作為整個小部件父級移動。 有關安全區域的更多信息,請參見此處https://api.flutter.dev/flutter/widgets/SafeArea-class.html

return SafeArea(
  child: Scaffold(
      extendBodyBehindAppBar: true,
      appBar: AppBar(
        backgroundColor: Colors.transparent,
        shadowColor: Colors.transparent,
        elevation: 0.0,
        title: Text('Title'),
      ),
      body: Container(
        decoration: BoxDecoration(
          image: DecorationImage(
            image: AssetImage('images/background_01.jpg'),
            fit: BoxFit.cover,
          ),
        ),
        child: Column(
          children: [
            Container(),
            Container(),
          ],
        ),
      )),
);

這里的解決方案

在此處輸入圖像描述

將這些行添加到您想要的位置

  SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
      statusBarColor: Colors.green,
    ));

這里的例子

 Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
  statusBarColor: Colors.green,
));

return Container(
  color: Colors.blue,
);}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM