Open josh-burton opened 3 years ago
Able to reproduce this on latest master
channel.
Is there a workaround for this?
Not that I found as it is hardcoded in the FlutterActivity. You could potentially create your own version of the FlutterActivity.
@blasten is the Android embedding your area of expertise? Any suggestions on this bug?
Just tried a release version of my app and it doesn't appear to be noticeable, so may just be an issue whilst debugging.
I have this issue (even in release mode) and it seems to have become more pronounced after moving from 1.20 to 1.22.
Just watching the app launch, the time between splash screen fading and widgets being drawn to the screen has increased (seemingly as a result of the splash screen being visible for a shorter time), which means the time that this darker status bar is present has increased as well. This unfortunately makes the app launch feel pretty sloppy.
1.20 - splash screen stays visible until just before flutter widgets are rendered, and the darkened status bar flashes only for a brief moment. Not perfect, but better than in 1.22 (below).
https://user-images.githubusercontent.com/6845951/104380784-2c2e1080-54f1-11eb-8cdd-11f545de9016.mp4
1.22 - splash screen theme is replaced by normal theme much quicker, and the darkened status bar is visible for a much longer time before flutter widgets are rendered.
https://user-images.githubusercontent.com/6845951/104380812-351ee200-54f1-11eb-9693-bfbab65b6ee9.mp4
For a generic example that shows this issue, see the examples in https://github.com/flutter/flutter/issues/73351. In this example they use a flutter based splash screen after the launch theme is switched to the normal theme, but you can still see the status bar switch color for a noticeable length of time before switching back to their configured color.
Any update or workaround on this?
Does it help at all if you set the status bar colour before runApp? For example:
...
import 'package:flutter/services.dart';
void main() {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Color(0x00000000),
));
runApp(MyApp());
}
...
@GrantSavill yes, this helps tremendously - not seeing the statusbar change in release mode anymore. Thank you very much!
@ajbeattie glad I could help!
This solves the issue for me, but only in release
mode.
Likely because release builds run a lot faster - which means that is a good work around but not a real fix as on slow devices the same issue could still appear.
I had the same problem, and i found that the widget that was changing the color, was the AppBar. I had
AppBar(
brightness: Brightness.dark,
backgroundColor: Colors.transparent,
iconTheme: IconThemeData(
color: context.read<GlobalBloc>().styles.theme.primaryColor),
elevation: 0,
)
i had to change it to brightness: Brightness.light,
any news?
it didn't help me
I encountered the same issue and it is as Josh said Flutter Activity is calling configureStatusBarForFullscreenFlutterExperience
but you can do some workaround.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// this is very important
window.statusBarColor = 0x000000
}
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
// customise here
statusBarIconBrightness: Brightness.dark,
),
);
With a light theme and a light status bar, the status bar is completely white. This way, there is no brightness change. Once Flutter is loaded, it will replace with the colour and brightness you want to set. It is not perfect but works for me. Tested on Flutter 2.0.3.
https://user-images.githubusercontent.com/6754708/112262023-0e371600-8cc1-11eb-8ff3-4b9dbcb73a23.mov
Try on the android's MainActivity, Override the oncreate method then after calling super, set window.statusBarColor = Color.TRANSPARENT
. This is just a workaround since Flutter activity automatically sets the status bar color. But by doing this is just reverting it back immediately to be transparent.
The engine sets a hardcoded bar color in a few places, which is likely happening before Dart starts executing (and this code runs).
Would anyone be interested in exploring a solution in that space? Maybe looking at the manifest, and if a custom color is set, avoid resetting the status bar color.
cc @xster for thoughts
Flutter should just keep the status bar color the same color as the android:statusBarColor
item (doc) of the NormalTheme in styles.xml - if set. Having it flicker between the launch screen color, then the seemingly unconfigurable theme color, then whatever color is set with setSystemUIOverlayType isn't a clean look.
This is what I am using. We only wanted to remove the black statusbar when the app is launching.
colors.xml
<color name="statusbar">#40000000</color>
styles.xml
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">@drawable/launch_background</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@color/statusbar</item>
</style>
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
@HenryQuan workaround works, these is a more complete example snippet.
MainActivity.kt
package com.example.app
import android.os.Bundle
import android.graphics.Color
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
window.setStatusBarColor(Color.TRANSPARENT);
}
}
main.dart
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
statusBarIconBrightness:
WidgetsBinding.instance!.platformDispatcher.platformBrightness ==
Brightness.light
? Brightness.dark
: Brightness.light,
),
);
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Material App',
theme: ThemeData.light(),
darkTheme: ThemeData.dark(),
home: Scaffold(
body: Center(
child: Container(
child: Text('Hello World'),
),
),
),
);
}
}
Any update on this? I am having the same issue as well :(
From what I understand, this issue is in someway fixed in flutter 2.5 with this https://flutter.dev/docs/development/ui/advanced/splash-screen#migrating-from-manifest--activity-defined-custom-splash-screens but not by default.
Flutter now automatically keeps the Android launch screen displayed until Flutter has drawn the first frame.
So I need to remove the meta tag io.flutter.embedding.android.SplashScreenDrawable
in AndroidManifest.xml
any news update? it is helpful for custom splash screen
@camsim99 FYI since you are working on #91128; see also b/201755161
Why just don't remove setStatusBarColor
in configureStatusBarForFullscreenFlutterExperience
?
Verified this issue using latest versions and using the code sample provided here and observed that the original issue persists as shown below:
Thank you. This fixed it for me.
> void main() {
> WidgetsFlutterBinding.ensureInitialized();
> SystemChrome.setSystemUIOverlayStyle(
> SystemUiOverlayStyle(
> statusBarIconBrightness:
> WidgetsBinding.instance!.platformDispatcher.platformBrightness ==
> Brightness.light
> ? Brightness.dark
> : Brightness.light,
> ),
> );
> runApp(MyApp());
> }
Android supports light/dark brightness for statusbar icons. On startup, the FlutterActivity always sets the status bar icons to light.
When trying to create an app with dark status bar icons, this causes a flicker between brightness on startup.
Steps to Reproduce
To reproduce, configure the Android theme to have a light status bar (dark icons):
In Flutter, also set the status bar icons to dark:
Expected result: On startup, the statusbar color and icon color should be consistent across the native startup sequence and as the Flutter engine/app starts.
Actual result: The app starts with the correct status bar/icon colors, then flickers to light status bar icons during startup, and once the Flutter app is running flicks back to dark statusbar icons.
A sample project can be found here.
The cause of the issue seems to be this method in io.flutter.embedding.android.FlutterActivity:
Either Flutter should set the status bar color/brightness to the existing Android theme settings, or provide a way to override these values in the theme or manifest metadata.
Logs
``` ➜ flutter doctor -v [✓] Flutter (Channel beta, 1.20.0, on Mac OS X 10.15.5 19F101, locale en-AU) • Flutter version 1.20.0 at /Users/athor/dev/flutter • Framework revision 916c3ac648 (2 weeks ago), 2020-08-01 09:01:12 -0700 • Engine revision d6ee1499c2 • Dart version 2.9.0 (build 2.9.0-21.10.beta) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.1) • Android SDK at /Users/athor/dev/android-sdk • Platform android-30, build-tools 30.0.1 • ANDROID_HOME = /Users/athor/dev/android-sdk • Java binary at: /Users/athor/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-1/201.6719854/Android Studio 4.1 Preview.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 11.6) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 11.6, Build version 11E708 • CocoaPods version 1.8.4 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 4.0) • Android Studio at /Users/athor/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-2/193.6626763/Android Studio.app/Contents • Flutter plugin version 47.1.2 • Dart plugin version 193.7361 • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) [!] Android Studio (version 4.1) • Android Studio at /Users/athor/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-1/201.6719854/Android Studio 4.1 Preview.app/Contents ✗ Flutter plugin not installed; this adds Flutter specific functionality. ✗ Dart plugin not installed; this adds Dart specific functionality. • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) [!] Android Studio • Android Studio at /Users/athor/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/201.6720134/Android Studio 4.2 Preview.app/Contents ✗ Flutter plugin not installed; this adds Flutter specific functionality. ✗ Dart plugin not installed; this adds Dart specific functionality. • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) [✓] IntelliJ IDEA Ultimate Edition (version 2020.2) • IntelliJ at /Users/athor/Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app • Flutter plugin version 48.0.4-dev.4 • Dart plugin version 202.6397.47 [✓] VS Code (version 1.47.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.12.2 [✓] Connected device (3 available) • Android SDK built for x86 64 (mobile) • emulator-5554 • android-x64 • Android 10 (API 29) (emulator) • Web Server (web) • web-server • web-javascript • Flutter Tools • Chrome (web) • chrome • web-javascript • Google Chrome 84.0.4147.125 ! Doctor found issues in 2 categories. ```