'How make the StatusBar transparent for Android in Flutter

I want to make the StatusBar transparent for Android in Flutter but for some reason I am getting black StatusBar on some of the screens. The minimum SDK is 20, targeting SDK 30.

I have tired all the suggestions from here but nothing works: How to hide Android StatusBar in Flutter

Also, I have tried the Flutter package for changing the StatusBar Color:

import 'package:flutter_statusbarcolor/flutter_statusbarcolor.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    FlutterStatusbarcolor.setStatusBarColor(Colors.transparent);
    ...
  }
}

And I have tried placing this code on every page:

@override
  initState() {
    SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
      statusBarColor: Colors.transparent,
    ));
    super.initState();
  }

With the two example codes above I only manage to make the StatusBar color transparent for the splash screen where I also have a background image. Example here: Transparent StatusBar

Once the application loads the StatusBar becomes black: Black StatusBar

Even more strange is when I switch trough the application screens, then the text in the StatusBar becomes black as well and remains this way until the application is restarted: enter image description here

I suppose the black Status Bar can be due to the theme settings or another setting in my app influencing the StatusBar but noting I have tried so far works.

Ideally, I want to make that StatusBar transparent and have the text changing between black and white depending on the background color. It is ok to manually set the transparency and text color as long as it works.

Any suggestions?



Solution 1:[1]

Inside your main.dart file, do this ->

void main() {
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
      statusBarColor: Colors.red));
  runApp(App(
  ));
}

This way you won't have to write the code in every file.

Solution 2:[2]

try this :

main :

void main() async {
  SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
    statusBarColor: Colors.teal,
    statusBarIconBrightness: Brightness.dark,
  ));

appbar :

AppBar(
                title: const Text('promoo'),
                centerTitle: true,
                bottomOpacity: 0,
                elevation: 0,
              ),

Solution 3:[3]

Try setting the Appbar transparent without any package, and set the default Theme do light.

Since I've never had this problem, my guess is that this should prevent some devices to make the statusbar black out.

void main() {
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
            statusBarColor: Colors.transparent));
  runApp(MyApp());
}

return MaterialApp(
      title: 'MyApp',
      themeMode: ThemeMode.light, //Forcing the ThemeMode could help you
      home: const Home(),
    );

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rahul Mishra
Solution 2 Kerby Elpenord
Solution 3 Dani3le_