Flutter中未定义“ SystemChrome”

时间:2019-05-07 12:26:45

标签: android flutter statusbar

我是Flutter的新手,我想更改应用程序的状态栏颜色。经过一番谷歌搜索后,我找到了一种方法。就是在我的main函数中添加以下代码。

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
  statusBarColor: Colors.white
));

但是添加并运行我的应用程序后,出现以下错误:-

Compiler message:                                                       
lib/main.dart:15:40: Error: Method not found: 'SystemUiOverlayStyle'.   
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(            
                                       ^^^^^^^^^^^^^^^^^^^^             
lib/main.dart:15:3: Error: Getter not found: 'SystemChrome'.            
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(            
  ^^^^^^^^^^^^                                              

请告诉我是什么问题。 预先感谢!


我的main函数:-

void main() {
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
    statusBarColor: Colors.white
  ));
  runApp(WilliamClient());
}

我的pubspec.yaml文件:-

name: william_client
description: Client App for William Assistant and TV.
version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  firebase_auth: 0.8.4+5
  cloud_firestore: 0.10.1
  flutter:
    sdk: flutter
  cupertino_icons: ^0.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:

  fonts:
    - family: Montserrat
      fonts:
        - asset: fonts/Montserrat.ttf
    - family: MontserratLight
      fonts:
        - asset: fonts/Montserrat-Light.ttf
    - family: RobotoMono
      fonts:
        - asset: fonts/RobotoMono.ttf

1 个答案:

答案 0 :(得分:1)

您应该添加

import 'package:flutter/services.dart';