Shardul Nalegave
Shardul Nalegave

Reputation: 409

'SystemChrome' not defined in Flutter

I am new to Flutter and I wanted to change the Status Bar color of my app. After some googling, I found a way to do so. It was to add the following code in my main function.

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

But after adding it and running my app I got the following error:-

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(            
  ^^^^^^^^^^^^                                              

Please tell me what is the problem. Thanks in advance!


My main function:-

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

My pubspec.yaml file:-

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

Upvotes: 4

Views: 4237

Answers (1)

user10539074
user10539074

Reputation:

you should add

import 'package:flutter/services.dart';

Upvotes: 14

Related Questions