Open In App

Flutter – Hide the Status Bar

Last Updated : 20 Dec, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

StatusBar is located at the top of the Application, which basically shows the notification of the phones. Sample images are given below to get an idea about what we are going to do in this article.

Before Hiding the status bar:

 

After Hiding the status bar:

 

If you see the difference between the images, In the first image status bar is shown but in the second image, status bar is filled with color or hidden.

Approach

Import the services package.

import 'package:flutter/services.dart';

You can bring it back with

SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: [SystemUiOverlay.bottom]);

Step By Step Implementation

Step 1: Create a New Project in Android Studio

To set up Flutter Development on Android Studio please refer to Android Studio Setup for Flutter Development, and then create a new project in Android Studio please refer to Creating a Simple Application in Flutter.

Step 2: Import the material package

Adding material package that gives us the important functions and calls the runApp method in the main function that will call our application.

import 'package:flutter/material.dart';
void main() {
   runApp(RunMyApp());
}

Step 3: Creating Stateless Widget

Now we have to make a stateful widget because our application does may  change its state and then return the materialApp widget which allows us the set the title and theme and many more or you can say default values.

class RunMyApp extends StatefulWidget {
  const RunMyApp({super.key});

  @override
  State<RunMyApp> createState() => _RunMyAppState();
}

class _RunMyAppState extends State<RunMyApp> {
 
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
);
  }
}

Step 4: Creating Scaffold Widget

Give the home property and there can be a scaffold widget that has the property of AppBar and body. AppBar allows us to give the title of AppBar, color, leading, and trailing icon. 

Step 5: Create the initState method that is the main part of the project.

 void initState() {
   // TODO: implement initState
   SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: [SystemUiOverlay.bottom]);
   super.initState();
 }

Final Code

Dart




import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
  
void main() {
    
  runApp(RunMyApp());
}
  
class RunMyApp extends StatefulWidget {
  const RunMyApp({super.key});
  
  @override
  State<RunMyApp> createState() => _RunMyAppState();
}
  
class _RunMyAppState extends State<RunMyApp> {
  @override
  void initState() {
    // TODO: implement initState
    SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: [SystemUiOverlay.bottom]);
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(primarySwatch: Colors.green),
      home: Scaffold(
        appBar: AppBar(
          title: Text('Hide Status Bar'),
        ),
      ),
    );
  }
}


Output

 



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads