简体   繁体   English

如何在 flutter 应用程序中更改状态栏的颜色

[英]how to change the color of statusbar in flutter app

Can Anybody tell me how the change the color of this statusbar into other colors.谁能告诉我如何将此状态栏的颜色更改为其他 colors。 As you can see in the following image it's a dark color and the time, battery, network details also shown in dark.正如您在下图中看到的那样,它是深色的,时间、电池、网络详细信息也以深色显示。 so that's making them invisible.所以这使它们不可见。 I either want to change the color dynamically like when the background color becomes dark the text color of the system widgets ( time, battery, network) becomes white and when color is light those becomes dark.我要么想动态更改颜色,例如当背景颜色变暗时,系统小部件(时间、电池、网络)的文本颜色变为白色,而当颜色变亮时,这些文本颜色变暗。

or If I have to hardcode the color each time.或者如果我每次都必须对颜色进行硬编码。 where should I do it?我应该在哪里做? Any solution will be appreciable.任何解决方案都将是可观的。 在此处输入图像描述

this package: https://pub.dev/packages/flutter_statusbarcolor这个 package: https://pub.dev/packages/flutter_statusbarcolor

import 'package:flutter_statusbarcolor/flutter_statusbarcolor.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    FlutterStatusbarcolor.setStatusBarColor(Colors.white);
    return MaterialApp(
      title: "Flutter",
      theme: ThemeData(
        primarySwatch: Colors.grey,
      ),
      home: HomeScreen(),
    );
  }
}

I found how to achieve this in flutter built in functions.我发现如何在 flutter 内置函数中实现这一点。 in MaterialApp go inside theme create AppBarTheme and give the property brightenss: Brightness.dark or Brightness.light based on your requirement.MaterialApp go theme内创建AppBarTheme并根据您的要求赋予属性brightenss: Brightness.dark or Brightness.light If your status bar color is dark then give Brightness.dark it will make icons and text in white color and vice versa for light background.如果您的状态栏颜色较暗,则给Brightness.dark它将使图标和文本为白色,反之亦然,用于浅色背景。

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

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