generateImageForAndroid12AndAbove function

Future<void> generateImageForAndroid12AndAbove({
  1. 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];
  final brandingImage = android12AndAbove[YamlKeys.brandingImageKey];

  if (image != null) {
    final sourceImage = File(android12AndAbove[YamlKeys.imageKey]);

    /// Checking if provided asset image source exist or not
    if (!await sourceImage.exists()) {
      throw SplashMasterException(message: 'Image path not found');
    }

    final drawableFolder = '$androidResDir/$drawable';
    final directory = Directory(drawableFolder);
    if (!(await directory.exists())) {
      log("$drawable folder doesn't exists. Creating it...");
      await Directory(drawableFolder).create(recursive: true);
    }

    /// Create image in drawable directories for the Android 12+
    final imagePath = '$drawableFolder/${AndroidStrings.splashImage12Png}';

    final file = File(imagePath);
    if (await file.exists()) {
      await file.delete();
    }

    /// Creating a splash image from the provided asset source
    await sourceImage.copy(imagePath);
    log("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';
    final directory = Directory(drawableFolder);
    if (!(await directory.exists())) {
      log("$drawable folder doesn't exists. Creating it...");
      await Directory(drawableFolder).create(recursive: true);
    }

    createBrandingImageForAndroid12(
      drawableFolder,
      sourceImage,
    );
  }
}