簡體   English   中英

刪除 AppBar 但在 Flutter 中保留 StatusBar

[英]Remove AppBar but keeping StatusBar in Flutter

如何在沒有 AppBar 的情況下為我的 StatusBar 設置自定義顏色?

要自定義 StatusBar 顏色,我使用了以下代碼:

appBar: AppBar(
    backgroundColor: Colors.teal
)

如果我刪除appbar ,我將無法自定義 StatusBar。 我怎么能做到這一點?

如何刪除 AppBar 但保留狀態欄?

將此添加到您的main.dart的 main 方法文件中runApp方法之后

SystemChrome.setSystemUIOverlayStyle(
        SystemUiOverlayStyle(statusBarColor: <YOUR STATUS BAR COLOR>));

像這樣:

void main(){
 runApp(MyApp());
SystemChrome.setSystemUIOverlayStyle(
            SystemUiOverlayStyle(statusBarColor: <YOUR STATUS BAR COLOR>));
}

如果您使用的是SafeArea ,則需要將其top屬性設置為false

你也可以使用這個

@override
Widget build(BuildContext context) {
   return Container(
     color: Your Color Here,
     child: SafeArea(
        bottom: false,
        child: Scaffold(
      ),
    ),
  );
}

您可以使用以下代碼更改狀態欄顏色第一步您必須導入下面給出的 package

" import 'package:flutter/services.dart';

然后將此代碼添加到您的 main.dart 文件中

void main(){SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(statusBarColor:Colors.blue,));}

我們可以簡單地使用AppBar來實現,在下面的代碼中backgroundColor: Colors.green應用於狀態欄。

Scaffold(
  appBar: AppBar(
    systemOverlayStyle: SystemUiOverlayStyle.dark,
    backgroundColor: Colors.green,
    elevation: 0,
    toolbarHeight: 0,
  ),
  backgroundColor: Colors.white38,
  body: Container(),
)

權限:

在此處輸入圖像描述

暫無
暫無

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

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