setupSplashScreen function
void
setupSplashScreen(
- YamlMap splashData
Setting up the splash screen using the details provided in pubspec.yaml
file under splash_master
.
Implementation
void setupSplashScreen(YamlMap splashData) {
/// Checking keys in the `splash_master` section in `pubspec.yaml` file is proper or not.
if (YamlKeys.supportedYamlKeys.any(
(element) => splashData.keys.any(
(e) => e == element,
),
)) {
IosContentMode? iosContentMode;
if (splashData[YamlKeys.iosContentModeKey] != null) {
iosContentMode =
IosContentMode.fromString(splashData[YamlKeys.iosContentModeKey]);
}
/// Checking if provided android gravity is valid or not
if (splashData[YamlKeys.androidGravityKey] != null &&
!(AndroidGravity.values.any(
(element) =>
element ==
AndroidGravity.fromString(splashData[YamlKeys.androidGravityKey]),
))) {
log('Please check the android_gravity');
return;
}
/// Checking if provided content mode is valid or not
else if (splashData[YamlKeys.iosContentModeKey] != null &&
!IosContentMode.values.any(
(element) => element == iosContentMode,
)) {
log('Please check the ios_content_mode');
return;
}
/// Checking if provided image has supported extension or not
else if (splashData[YamlKeys.imageKey] != null) {
final imgExtension =
splashData[YamlKeys.imageKey].toString().split('.').last;
if (!SupportedImageExtensions.values.any(
(element) =>
element ==
SupportedImageExtensions.fromString(imgExtension.toLowerCase()),
)) {
log('Image should be png or jpg');
return;
}
} else if (splashData[YamlKeys.androidBackgroundGravity] != null &&
!(AndroidGravity.values.any(
(element) =>
element ==
AndroidGravity.fromString(
splashData[YamlKeys.androidBackgroundGravity]),
))) {
log('Please check the android_background_image_gravity');
return;
}
applySplash(
imageSource: splashData[YamlKeys.imageKey],
color: splashData[YamlKeys.colorKey],
gravity: splashData[YamlKeys.androidGravityKey],
iosContentMode: iosContentMode?.mode,
backgroundImage: splashData[YamlKeys.backgroundImage],
android12AndAbove: splashData[YamlKeys.android12AndAboveKey],
iosBackgroundContentMode: splashData[YamlKeys.iosBackgroundContentMode],
backgroundImageSource: splashData[YamlKeys.backgroundImage],
backgroundImageGravity: splashData[YamlKeys.androidBackgroundGravity],
darkColor: splashData[YamlKeys.colorDarkAndroid],
darkGravity: splashData[YamlKeys.androidGravityKey],
darkImage: splashData[YamlKeys.imageDarkAndroid],
);
}
}