Flutter:在iOS中更改状态栏颜色

时间:2019-10-07 13:37:43

标签: flutter dart flutter-layout

我想使用 File "/usr/lib64/python3.6/site-packages/pandas/core/indexes/base.py", line 2890, in get_loc return self._engine.get_loc(key) File "pandas/_libs/index.pyx", line 107, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 131, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 1607, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 1614, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: '1992-03-01' 包更改状态栏的颜色,但是不起作用。我正在使用Mac和iOS模拟器:

  • 莫哈韦沙漠10.14.6
  • iOS 12.2模拟器/ Xr
  • Flutter 1.9.1 + hotfix.2
  • 工具•Dart 2.5.0
package:flutter/services.dart

enter image description here

即使我将其放在import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) { SystemChrome.setSystemUIOverlayStyle( SystemUiOverlayStyle( statusBarColor: Colors.red // <-- doesn't work ) ); return MaterialApp( title: 'Flutter Demo', theme: ThemeData( // This is the theme of your application. // // Try running your application with "flutter run". You'll see the // application has a blue toolbar. Then, without quitting the app, try // changing the primarySwatch below to Colors.green and then invoke // "hot reload" (press "r" in the console where you ran "flutter run", // or simply save your changes to "hot reload" in a Flutter IDE). // Notice that the counter didn't reset back to zero; the application // is not restarted. primarySwatch: Colors.blue, ), home: MyHomePage(title: 'Flutter Demo Home Page'), ); } } ... // other stuff 函数中,也是如此:

main

结果是,如果我想将import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; void main() { SystemChrome.setSystemUIOverlayStyle( SystemUiOverlayStyle( statusBarColor: Colors.red, ) ); SystemChrome.setPreferredOrientations( [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]) .then((_) => runApp(MyApp())); } ... // the rest code here 背景颜色更改为白色,则会得到此信息。

enter image description here

还没有针对Android进行过测试。此问题仅与iOS模拟器有关吗?如何解决?

U.P.D。

这个问题开始让我发疯。

3 个答案:

答案 0 :(得分:1)

尝试

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: PreferredSize(
    preferredSize: Size.fromHeight(0),
    child: AppBar( // Here we create one to set status bar color
      backgroundColor: Colors.black, // Set any color of status bar you want; 
 or it defaults to your theme's primary color
    )
  )
);
}

答案 1 :(得分:0)

修改:

appBar: AppBar(
  elevation: 0,
  brightness: Brightness.light, // this makes status bar text color black
  backgroundColor: Colors.white,
)

输出:

enter image description here


statusBarColor只能在Android中更改,而不能在iOS中进行更改,并且如果您尝试通过某些变通办法拒绝苹果的应用程序,可能是苹果可以拒绝您的应用程序,因为他们不希望您使用不同的AppBar并且状态栏颜色。

AppBar(backgroundColor: Colors.red) // this changes both AppBar and status bar color in iOS

Apple希望您坚持自己的设计,这就是更改statusBarColor对iOS没有影响的原因。

答案 2 :(得分:-1)

尝试一下:

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark.copyWith(
  statusBarColor: Colors.white, // this one for android
  statusBarBrightness: Brightness.light// this one for iOS
));