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):
Here are some solutions I've tried:
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):
<item name="android:windowTranslucentNavigation">true</item>
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?
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
Solution. In summary, we can make a transparent app bar by set backgroundColor to Colors. transparent (1), elevation to 0 (2), and title color to anything different from background color (3).
Creating a transparent navbar is very easy - just don't add a color class . bg-* to the navbar. In this case, the Navbar will take the color of the parent's background color.
From Settings, tap Display, and then tap Navigation bar. Make sure Buttons is selected, and then you can choose your desired button setup at the bottom of the screen. Note: This option will also affect the location you swipe when using Swipe gestures.
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 } }
Remove SystemChrome.setSystemUIOverlayStyle commands from your main.dart
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With