【发布时间】:2020-02-04 19:38:41
【问题描述】:
我想用package:flutter/services.dart 包更改状态栏颜色,但它不起作用。我正在使用 Mac 和 iOS 模拟器:
- 莫哈韦 10.14.6
- iOS 12.2 模拟器/Xr
- Flutter 1.9.1+hotfix.2
- 工具• Dart 2.5.0
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
因此,如果我想将 appBar 背景颜色更改为白色,我会得到这个。
尚未针对 android 测试它。这个问题仅与iOS模拟器有关吗?如何解决?
U.P.D.
这个问题让我抓狂了。
【问题讨论】:
标签: flutter dart flutter-layout