颤动应用程序更改状态栏以匹配相同的应用程序栏

时间:2020-04-11 13:48:18

标签: android flutter flutter-layout flutter-test

嗨,我正在尝试更改状态栏,使其与我的应用栏颜色保持一致,但我没有运气,我试图这样做:

@override
  Widget build(BuildContext context) {
    return Scaffold(
      body: AnnotatedRegion<SystemUiOverlayStyle>(
        value: SystemUiOverlayStyle(statusBarColor: Colors.black,
        systemNavigationBarColor: Colors.black),

但是我的状态栏仍然像这样:

enter image description here

但是在iPhone上,它可以正确显示颜色

enter image description here

1 个答案:

答案 0 :(得分:1)

导入

import 'package:flutter/services.dart';

并将此代码添加到主窗口小部件树中:

@override
  Widget build(BuildContext context) {

    SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
      statusBarColor: Colors.blue,
      statusBarBrightness: Brightness.dark, // as you need dark or light
    ));

return MaterialApp(home: yourHomeWidgetWhereTheScaffoldIsDefined....

希望这会有所帮助