现象:打开Flutter对应的Activity(io.flutter.app.FlutterFragmentActivity
),因为第一次渲染慢,会闪一下黑屏
解决方案:
AndroidManifest添加meta-data
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true"/>
代码如下:
<activity
android:name=".flutter.FlutterActivity"
android:hardwareAccelerated="true"
android:screenOrientation="portrait"
android:theme="@style/FlutterTheme">
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true"/>
</activity>
<style name="FlutterTheme" parent="AppTheme">
<item name="android:windowBackground">@color/white</item>
<item name="android:statusBarColor">@color/white</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowAnimationStyle">@style/windowAnimation</item>
</style>
IOS同理
代码如下:
#pragma mark - life cycle
- (instancetype)init {
self = [super init];
if (self) {
UIView *view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
view.backgroundColor = [UIColor whiteColor];
self.splashScreenView = view;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (self.navigationController) {
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
}
@end