applyAndroidSplashImage function
Generates Android splash assets and updates Android resource files.
It creates splash images (including optional dark/background variants),
generates Android 12+ assets from android12AndAbove, writes color resources,
builds splash drawable XMLs for light and dark themes, updates styles.xml,
and updates dark styles when any dark-mode input is provided.
Implementation
Future<void> applyAndroidSplashImage({
String? imageSource,
String? color,
String? gravity,
YamlMap? android12AndAbove,
String? backgroundImageSource,
String? backgroundImageGravity,
String? darkImage,
String? darkColor,
String? darkGravity,
String? darkBackgroundImageSource,
}) async {
await generateAndroidImages(
imageSource: imageSource,
darkImageSource: darkImage,
);
if (backgroundImageSource != null) {
await generateAndroidImages(
imageSource: backgroundImageSource,
backgroundImageName: AndroidStrings.splashBackgroundImagePng,
);
}
if (darkBackgroundImageSource != null) {
await generateAndroidImages(
imageSource: darkBackgroundImageSource,
backgroundImageName: AndroidStrings.splashBackgroundImageDarkPng,
);
}
await generateImageForAndroid12AndAbove(
android12AndAbove: android12AndAbove,
);
await createColors(color: color ?? AndroidStrings.defaultLightColor);
if (darkColor != null) {
await createColors(color: darkColor, isDark: true);
}
await createSplashImageDrawable(
imageSource: imageSource,
color: color ?? AndroidStrings.defaultLightColor,
gravity: gravity,
backgroundImageSource: backgroundImageSource,
backgroundImageGravity: backgroundImageGravity,
);
await createDarkSplashImageDrawable(
darkImage: darkImage,
color: darkColor,
gravity: darkGravity ?? gravity,
darkBackgroundImageSource: darkBackgroundImageSource,
backgroundImageGravity: backgroundImageGravity,
);
await updateStylesXml(
android12AndAbove: android12AndAbove,
hasDarkDrawable: darkImage != null ||
darkColor != null ||
darkBackgroundImageSource != null,
);
final darkBrandingImage = android12AndAbove?[YamlKeys.brandingImageDarkKey];
// Always call updateDarkStylesXml — it will remove existing dark-style files
// when no dark configuration is provided, avoiding stale references.
await updateDarkStylesXml(
android12AndAbove: android12AndAbove,
darkColor: darkColor,
darkImage: darkImage,
darkBrandingImage: darkBrandingImage,
darkBackgroundImageSource: darkBackgroundImageSource,
);
}