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 && darkImageSource == 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';
  await _ensureDirectoryExists(
    drawableFolder,
    logMessage: "$drawable folder doesn't exists. Creating it...",
  );

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

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

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