我正在尝试改变状态栏的颜色为白色。我偶然发现了这家酒吧。我尝试在我的dart文件中使用示例代码。
当前回答
使它像你的应用程序栏颜色
import 'package:flutter/material.dart';
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
systemNavigationBarColor: Colors.transparent,
));
}
其他回答
我不能直接在帖子中评论,因为我还没有必要的声誉,但作者问了以下问题:
唯一的问题是背景是白色的,但时钟,无线和其他文本和图标也是白色的。我不知道为什么!!
对于任何来到这个帖子的人来说,这是对我有用的方法。状态栏的文本颜色由flutter/material.dart中的亮度常数决定。要改变这一点,调整SystemChrome解决方案,如下所示来配置文本:
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.red,
statusBarBrightness: Brightness.dark,
));
亮度的可能值为亮度。黑暗和光明。
文档: https://api.flutter.dev/flutter/dart-ui/Brightness-class.html https://api.flutter.dev/flutter/services/SystemUiOverlayStyle-class.html
return Scaffold(
backgroundColor: STATUS_BAR_COLOR_HERE,
body: SafeArea(
child: scaffoldBody(),
),
);
对于那些有iOS和Android颜色不一致的问题的人来说,这个方法对我来说很管用:
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
return AppBar(
systemOverlayStyle: (Platform.isIOS)
? SystemUiOverlayStyle.light
: const SystemUiOverlayStyle(
statusBarColor: pbsBlue,
statusBarIconBrightness: Brightness.light,
statusBarBrightness: Brightness.light,
),
backgroundColor: Colors.blue,
title: Text('Home'),
);
请注意,这是AppBar可重用小部件的摘录。
如果你想改变整个应用程序的状态颜色,你可以像这样使用primaryColorDark属性:
void main() {
runApp(
MaterialApp(
home: HomeWidget(),
theme: ThemeData(
primaryColorDark: Colors.white,
),
),
);
}
你可以这样做,
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
statusBarColor: Colors.grey.withOpacity(0.5),
statusBarIconBrightness: Brightness.dark,
statusBarBrightness:
Platform.isAndroid ? Brightness.dark : Brightness.light,
systemNavigationBarColor: Colors.white,
systemNavigationBarDividerColor: Colors.grey,
systemNavigationBarIconBrightness: Brightness.dark,
),
);
将此代码添加到主程序中。省道构建方法,