generateAndroidImages function

Future<void> generateAndroidImages({
  1. String? imageSource,
  2. String? backgroundImageName,
  3. String? darkImageSource,
})

Generate splash images for the Android

Implementation

Future<void> generateAndroidImages({
  String? imageSource,
  String? backgroundImageName,
  String? darkImageSource,
}) async {
  if (imageSource == null) {
    log('No images were provided. Skipping generating Android images');
    return;
  }
  const androidResDir = CmdStrings.androidResDirectory;

  final drawable = getAndroidDrawable();

  /// Create splash images with the provided image in drawable directories
  final drawableFolder = '$androidResDir/$drawable';
  if (!await Directory(drawableFolder).exists()) {
    log("$drawable folder doesn't exists. Creating it...");
    await Directory(drawableFolder).create(recursive: true);
  }

  final imagePath =
      '$drawableFolder/${backgroundImageName ?? AndroidStrings.splashImagePng}';
  final file = File(imagePath);
  if (await file.exists()) {
    await file.delete();
  }
  final sourceImage = File(imageSource);
  if (await sourceImage.exists()) {
    /// Creating a splash image from the provided asset source
    sourceImage.copySync(imagePath);
  } else {
    throw SplashMasterException(message: 'Asset not found. $imagePath');
  }

  if (darkImageSource != null) {
    generateAndroidDarkImage(darkImageSource, drawableFolder);
  }

  log("Splash image added to $drawable");
}