generateImageForAndroid12AndAbove function
Future<void>
generateImageForAndroid12AndAbove(
{ - YamlMap? android12AndAbove,
})
Implementation
Future<void> generateImageForAndroid12AndAbove({
YamlMap? android12AndAbove,
}) async {
if (android12AndAbove == null) {
log('Skipping Android 12 configuration as it is not provided.');
return;
}
const androidResDir = CmdStrings.androidResDirectory;
final drawable = getAndroidDrawable(android12: true);
final image = android12AndAbove[YamlKeys.imageKey] as String?;
final brandingImage = android12AndAbove[YamlKeys.brandingImageKey];
final brandingImageDark = android12AndAbove[YamlKeys.brandingImageDarkKey];
if (image != null) {
final sourceImage = File(image);
/// Checking if provided asset image source exist or not
if (!await sourceImage.exists()) {
throw SplashMasterException(message: 'Image path not found');
}
final drawableFolder = '$androidResDir/$drawable';
await _ensureDirectoryExists(
drawableFolder,
logMessage: "$drawable folder doesn't exists. Creating it...",
);
/// Create image in drawable directories for the Android 12+
final imagePath = '$drawableFolder/${AndroidStrings.splashImage12Png}';
/// Creating a splash image from the provided asset source
await _replaceFileFromSource(
source: sourceImage,
destinationPath: imagePath,
);
log("Splash image added to $drawable");
}
/// Copy dark splash icon for Android 12+ dark mode
final imageDark = android12AndAbove[YamlKeys.imageDarkKey];
if (imageDark != null) {
final sourceDarkImage = File(imageDark);
/// Checking if provided dark asset image source exists or not
if (!await sourceDarkImage.exists()) {
throw SplashMasterException(
message: 'Android 12+ dark image path not found: $imageDark.');
}
final drawableFolder = '$androidResDir/$drawable';
await _ensureDirectoryExists(
drawableFolder,
logMessage: "$drawable folder doesn't exist. Creating it...",
);
final darkImagePath =
'$drawableFolder/${AndroidStrings.splashImage12DarkPng}';
await _replaceFileFromSource(
source: sourceDarkImage,
destinationPath: darkImagePath,
);
log("Android 12+ dark splash image added to $drawable");
}
if (brandingImage != null) {
final sourceImage = File(brandingImage);
/// Checking if provided asset image source exist or not
if (!await sourceImage.exists()) {
throw SplashMasterException(message: 'Branding Image path not found');
}
final drawableFolder = '$androidResDir/$drawable';
await _ensureDirectoryExists(
drawableFolder,
logMessage: "$drawable folder doesn't exists. Creating it...",
);
createBrandingImageForAndroid12(
drawableFolder,
sourceImage,
);
}
/// Copy dark branding image for Android 12+ dark mode
if (brandingImageDark != null) {
final sourceImage = File(brandingImageDark);
/// Checking if provided asset image source exist or not
if (!await sourceImage.exists()) {
throw SplashMasterException(
message: 'Dark branding image path not found: $brandingImageDark.');
}
final drawableFolder = '$androidResDir/$drawable';
await _ensureDirectoryExists(
drawableFolder,
logMessage: "$drawable folder doesn't exists. Creating it...",
);
final imagePath =
'$drawableFolder/${AndroidStrings.android12BrandingImageDark}';
await _replaceFileFromSource(
source: sourceImage,
destinationPath: imagePath,
);
log("Dark branding image added to $drawable");
}
}