简体   繁体   English

状态栏颜色 - Flutter

[英]Status Bar Color - Flutter

I need red status bar with white foreground for my entire app.我的整个应用程序都需要带有白色前景的红色状态栏。

I'm using flutter_statusbarcolor package for this.我为此使用了flutter_statusbarcolor package。

I did the following so far:到目前为止,我做了以下事情:

  1. Added the package in pubsec.yaml在 pubsec.yaml 中添加了 package
  2. Imported the package in my main.dart file在我的 main.dart 文件中导入了 package
  3. Added the following lines of codes inside the build() of MyApp class在 MyApp class 的build()中添加了以下代码行
    FlutterStatusbarcolor.setStatusBarColor(Colors.red[900]);    
    FlutterStatusbarcolor.setStatusBarWhiteForeground(true);

Result:结果:

  1. The status bar's color is red(working as it should).状态栏的颜色为红色(正常工作)。
  2. The foreground color is white.前景色为白色。 But on restart changes to black.但是在重新启动时变为黑色。 On hot reload, changes back to white.在热重载时,变回白色。 But on restart, it'll change back to black.但是在重新启动时,它会变回黑色。

Here is my complete code:这是我的完整代码:

import 'package:flutter_statusbarcolor/flutter_statusbarcolor.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  
  @override
  Widget build(BuildContext context) {
    FlutterStatusbarcolor.setStatusBarColor(Colors.red[900]);
    FlutterStatusbarcolor.setStatusBarWhiteForeground(true);
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'App Title',
      home: HomeScreen(),
    );
  }
}

I've also tried the following:我还尝试了以下方法:

  1. SystemChrome.setSystemUIOverlayStyle()
  2. appBarTheme: Theme.of(context).appBarTheme.copyWith(brightness: Brightness.light)

Nothing's working.没有任何工作。 Can anyone please help me sustain the white foreground throughout the app?谁能帮我维持整个应用程序的白色前景?

You can try this from this Doc ==> setSystemUIOverlayStyle method您可以从此 Doc ==> setSystemUIOverlayStyle 方法尝试此操作

Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
        statusBarColor: Colors.red,
    );
    return Placeholder();  // using As your Need
}

add this:添加这个:

import 'package:flutter/services.dart'

use the code below after theme data在主题数据之后使用下面的代码

 home: AnnotatedRegion<SystemUiOverlayStyle>(
      value: SystemUiOverlayStyle(
        statusBarColor: Colors.transparent,

Hope it work...希望它工作...

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

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