67

I would like to make my Flutter app take up the entire screen in Android while still showing both the status bar and the navigation bar, with both of them transparent, to achieve the full screen look like in iOS.

The status bar color can be easily changed, but right now I'm facing problems with getting the app to fill up the screen and making the navigation bar transparent at the same time.

By default, the app is not drawn below the navigation bar at all (I've set the status bar color to be transparent):

default app without modifications

Here are some solutions I've tried:

1) Setting flags on window in the onCreate function in MainActivity

Solution taken from here: https://stackoverflow.com/a/31596735

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, 
    WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
}

This sort of achieves what I want, but it has several problems. The padding and inset values in MediaQuery are now 0, so I have to manually get the status bar and nav bar heights through the use of MethodChannel. Furthermore, this creates a weird bug regarding the application switcher, as shown below (see how the content jumps and the debug banner on the top right is stretched):

solution 1 bug

2) Adding translucent navigation in styles.xml

<item name="android:windowTranslucentNavigation">true</item>

Result:

solution 2 result

This is the closest to what I want to achieve. MediaQuery.of(context).padding.top correctly shows the top padding, and MediaQuery.of(context).viewInsets.bottom correctly shows the height of the navbar. There are no weird bugs in the application switcher as well. The only problem is that the navbar is translucent and not transparent.

Here's the repo for the sample app shown above: https://github.com/CZX123/navbar

It would be nice if Flutter could provide this functionality out of the box. But it doesn't, so are there any other better ways to achieve this?

Update

It seems like we would have to wait for the Flutter team to officially implement this feature:
https://github.com/flutter/flutter/issues/40974
https://github.com/flutter/flutter/issues/34678

This comment also perfectly sums up the current behavior in Android: https://github.com/flutter/flutter/issues/34678#issuecomment-536028077

2
  • No, this is not what this about. This issue is about the actual system UI navigation (as introduced in Android Q) not rendering properly in Flutter. Commented Nov 7, 2020 at 1:17
  • Did you find any solution to make the system navigation bar transparent? Commented Feb 24, 2021 at 15:18

11 Answers 11

32

After Flutter 2.5.0:

This works for me like charm!

Inside your main() paste the code below:

//Setting SysemUIOverlay
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
    systemStatusBarContrastEnforced: true,
    systemNavigationBarColor: Colors.transparent,
    systemNavigationBarDividerColor: Colors.transparent,
    systemNavigationBarIconBrightness: Brightness.dark,
    statusBarIconBrightness: Brightness.dark)
);
    
//Setting SystmeUIMode
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge, overlays: [SystemUiOverlay.top]);
Sign up to request clarification or add additional context in comments.

2 Comments

This should be selected as the answer to this question!
Yes, this should be the selected answer, as edge to edge mode is now the default from Android 15 (APK 35) forward
9

There is a simple way to get around this using flutter natively on android SDK 29 and later without having to edit any other source file.

spoiler : instead of Colors.transparent use any color with 0.002 Opacity.

firstly you need to set the SystemUiMode to fullscreen display with status and navigation elements rendered over the application.

SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);

Then set the color of the navigation bar in setSystemUIOverlayStyle to any color with opacity of 0.002 (It's the minimum value you can use)

  SystemChrome.setSystemUIOverlayStyle(
    SystemUiOverlayStyle(
      systemNavigationBarColor: Colors.black.withOpacity(0.002),
    ),
  );

the result :

If you focus too hard, you may notice a slight color difference, however you can go further and set the navigation bar color to the background color and you won't notice any difference.

I use a global function to set it when changing the app theme

void setSystemUIOverlayStyle(final Color color) {
  SystemChrome.setSystemUIOverlayStyle(
    SystemUiOverlayStyle(
      systemNavigationBarColor: color.withOpacity(0.002),
    ),
  );
}

I don't know what is the issue with the transparent color but if the color is nearly transparent then everything will work fine.

3 Comments

it will glith if you wanna use dialog... we need the dialog overlay are covered entire screen
@Umar No, it works as expected with dialog/overlay, just don't use SafeArea
btw i just leaved flutter for now cause laggy, janky animation issue, i switched to native with jetpack compose
3

I achieved the transparency effect throughout my app easily by editing the following files

1.Add the following lines in android/app/build.gradle

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.5.0-beta01' //add this line
}

2.Add the following in your android/app/src/main/kotlin/com/<your_domain>/<your_project_name>/MainActivity.kt

import androidx.core.view.WindowCompat //add this line
import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
    //add the following block of code
    override fun onPostResume() {
        super.onPostResume()
        WindowCompat.setDecorFitsSystemWindows(window, false)
        window.navigationBarColor = 0 //for transparent nav bar
        window.statusBarColor = 0 //for transparent status bar
    }
}
  1. Remove SystemChrome.setSystemUIOverlayStyle commands from your main.dart

  2. Run flutter clean and re run your app.

NOTE:

  • In case you nest a stack direct under the scaffold for some screen, you might see your app drawing above nav bar. To fix that just set the following property on scaffold

    resizeToAvoidBottomInset: false

  • If you use an appbar or safeArea you might need to override the SystemUIOverlayStyle again using AnnotatedRegion

Comments

2

Though I don't know, which side effects this approach might cause, I believe it offers a solution to your question:

Scaffold(
  primary: false,
  appBar: AppBar(
    primary: false,
    // ...
  ),
  // ...
)

Setting both the Scaffold's and the AppBar's primary property to false removes their inner SafeArea, which renders them behind system UI.

Comments

2

The following worked for me:

build.gradle (app)

implementation 'androidx.core:core-ktx:1.5.0-rc01'

MainActivity.kt

class MainActivity: FlutterActivity() {

    override fun onPostResume() {
        super.onPostResume()
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            WindowCompat.setDecorFitsSystemWindows(window, false)
            window.navigationBarColor = 0
        }
    }
}

main.dart

void main() {
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark.copyWith(
    systemNavigationBarColor: Colors.transparent,
    statusBarColor: Colors.transparent,
  ));
  runApp(MyApp());
}

Inspiration came from https://github.com/flutter/flutter/issues/40974

2 Comments

Updating build.gradle and MainActivity worked for me.
error FlutterError (No MaterialLocalizations found. on i added dialog
1

as last flutter 3.19.x

your code main activity its worked for me and the MediaQuery have excact value not 0, tested in android 14

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, 
    WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
}

Comments

0

This is what I have been using on my main screen widget:

1 - To extend the app area over the navigation bar

  @override
  void initState() {
    super.initState();
    SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: [SystemUiOverlay.top]);
  }

2 - To make both the status and navigation bars transparent according to the current theme brightness:

  @override
  Widget build(BuildContext context) {
    Brightness currentBrightness = Theme.of(context).brightness;
    Brightness oppositeBrightness = currentBrightness == Brightness.light ? Brightness.dark : Brightness.light;
    return Scaffold(
      appBar: AppBar(
        systemOverlayStyle: SystemUiOverlayStyle(
          statusBarColor: Colors.transparent,
          statusBarBrightness: currentBrightness,
          statusBarIconBrightness: oppositeBrightness,
          systemNavigationBarColor: Colors.transparent,
          systemNavigationBarIconBrightness: oppositeBrightness,
        ),
        /* ... */
      ),
      /* ... */
    );
  }

1 Comment

does it from 1 to 2 or choose one?
0

Just enable edge to edge screen

SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge); // Enable Edge-to-Edge on Android 10+
    SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
      systemNavigationBarColor: Colors.transparent, // Setting a transparent navigation bar color
    ));

Comments

-1

So if you are using Flutter the procedure is:

  1. Set AppBar() color to transparent.
  2. Set extendBeyondAppBar to true.
  3. Set elevation to 0.

As an example:

    return Scaffold(
        extendBodyBehindAppBar: true,
        appBar: AppBar(
           elevation: 0,
           )

2 Comments

This is not about the navigation bar.
This is not the correct answer. This is about the modern Android behavior where a small gesture navigation bar is drawn over the app.
-4
return Scaffold(
   body: AnnotatedRegion<SystemUiOverlayStyle>(
    value: SystemUiOverlayStyle(
      statusBarColor: Colors.transparent,
      systemNavigationBarColor: Colors.transparent
    ),
    sized: false,
    child: Container(color: Colors.red)
  )
);

Comments

-4

This might be late, but the latest version for flutter, 1.12 provides a feature to draw the app behind the NavigationBar, so the following code will have the transparent navigation bar with app fully extended behind the navigation bar,

Scaffold(
  extendBodyBehindAppBar: true, //this ensures that the body is drawn behind the navigation bar as well
  appBar: AppBar(
    backgroundColor: Colors.transparent,
    title: Text('Transparent Bar'),
  ),
  body: Container(
    color: Colors.blue,
  ),
);

1 Comment

only works for AppBar, doesn't extend behind system navigation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.