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;
/// Create splash images with the provided image in mipmap directories
for (final mipmap in AndroidMipMaps.values) {
final mipmapFolder = '$androidResDir/${mipmap.folder}';
final directory = Directory(mipmapFolder);
if (!(await directory.exists())) {
log("${mipmap.folder} folder doesn't exists. Creating it...");
await Directory(mipmapFolder).create(recursive: true);
}
/// Create image in mipmap directories for the Android 12+
if (android12AndAbove[YamlKeys.imageKey] != null) {
final imagePath = '$mipmapFolder/${AndroidStrings.splashImage12Png}';
final file = File(imagePath);
if (await file.exists()) {
await file.delete();
}
final sourceImage = File(android12AndAbove[YamlKeys.imageKey]);
if (await sourceImage.exists()) {
/// Creating a splash image from the provided asset source
sourceImage.copySync(imagePath);
} else {
throw SplashMasterException(message: 'Image path not found');
}
log("Splash image added to ${mipmap.folder}");
}
}
}