createSplashByConfig function

void createSplashByConfig(
  1. Map<String, dynamic> config
)

Create splash screens for Android, iOS and HarmonyOS based on a config argument

Implementation

void createSplashByConfig(Map<String, dynamic> config) {
  // Preparing all the data for later usage
  final String? image =
      _checkImageExists(config: config, parameter: _Parameter.image);
  final String? imageAndroid =
      _checkImageExists(config: config, parameter: _Parameter.imageAndroid);
  final String? imageIos =
      _checkImageExists(config: config, parameter: _Parameter.imageIos);
  final String? imageHarmony =
      _checkImageExists(config: config, parameter: _Parameter.imageHarmony);
  final String? imageWeb =
      _checkImageExists(config: config, parameter: _Parameter.imageWeb);
  final String? darkImage =
      _checkImageExists(config: config, parameter: _Parameter.darkImage);
  final String? darkImageAndroid =
      _checkImageExists(config: config, parameter: _Parameter.darkImageAndroid);
  final String? darkImageIos =
      _checkImageExists(config: config, parameter: _Parameter.darkImageIos);
  final String? darkImageHarmony =
      _checkImageExists(config: config, parameter: _Parameter.darkImageHarmony);
  final String? darkImageWeb =
      _checkImageExists(config: config, parameter: _Parameter.darkImageWeb);
  final String? brandingImage =
      _checkImageExists(config: config, parameter: _Parameter.brandingImage);
  final String? brandingImageAndroid = _checkImageExists(
      config: config, parameter: _Parameter.brandingImageAndroid);
  final String? brandingImageIos =
      _checkImageExists(config: config, parameter: _Parameter.brandingImageIos);
  final String? brandingImageWeb =
      _checkImageExists(config: config, parameter: _Parameter.brandingImageWeb);
  final String? brandingDarkImage = _checkImageExists(
      config: config, parameter: _Parameter.brandingDarkImage);
  final String? brandingDarkImageAndroid = _checkImageExists(
      config: config, parameter: _Parameter.brandingDarkImageAndroid);
  final String? brandingDarkImageIos = _checkImageExists(
      config: config, parameter: _Parameter.brandingDarkImageIos);
  final String? brandingDarkImageWeb = _checkImageExists(
      config: config, parameter: _Parameter.brandingDarkImageWeb);
  final String? color = parseColor(config[_Parameter.color]);
  final String? colorAndroid = parseColor(config[_Parameter.colorAndroid]);
  final String? colorIos = parseColor(config[_Parameter.colorIos]);
  final String? colorHarmony = parseColor(config[_Parameter.colorHarmony]);
  final String? colorWeb = parseColor(config[_Parameter.colorWeb]);
  final String? darkColor = parseColor(config[_Parameter.darkColor]);
  final String? darkColorAndroid =
      parseColor(config[_Parameter.darkColorAndroid]);
  final String? darkColorIos = parseColor(config[_Parameter.darkColorIos]);
  final String? darkColorHarmony =
      parseColor(config[_Parameter.darkColorHarmony]);
  final String? darkColorWeb = parseColor(config[_Parameter.darkColorWeb]);
  final String? backgroundImage =
      _checkImageExists(config: config, parameter: _Parameter.backgroundImage);
  final String? backgroundImageAndroid = _checkImageExists(
      config: config, parameter: _Parameter.backgroundImageAndroid);
  final String? backgroundImageIos = _checkImageExists(
      config: config, parameter: _Parameter.backgroundImageIos);
  final String? backgroundImageHarmony = _checkImageExists(
      config: config, parameter: _Parameter.backgroundImageHarmony);
  final String? backgroundImageWeb = _checkImageExists(
      config: config, parameter: _Parameter.backgroundImageWeb);
  final String? darkBackgroundImage = _checkImageExists(
      config: config, parameter: _Parameter.darkBackgroundImage);
  final String? darkBackgroundImageAndroid = _checkImageExists(
    config: config,
    parameter: _Parameter.darkBackgroundImageAndroid,
  );
  final String? darkBackgroundImageIos = _checkImageExists(
      config: config, parameter: _Parameter.darkBackgroundImageIos);
  final String? darkBackgroundImageHarmony = _checkImageExists(
      config: config, parameter: _Parameter.darkBackgroundImageHarmony);
  final String? darkBackgroundImageWeb = _checkImageExists(
      config: config, parameter: _Parameter.darkBackgroundImageWeb);

  final plistFiles = config[_Parameter.plistFiles] as List<String>?;
  final harmonyModuleJsonFile = config[_Parameter.harmonyModuleJson] as String?;
  final harmonyIndexEtsFile = config[_Parameter.harmonyIndexEts] as String?;
  String gravity = (config['fill'] as bool? ?? false) ? 'fill' : 'center';
  if (config[_Parameter.gravity] != null) {
    gravity = config[_Parameter.gravity] as String;
  }
  final String? androidScreenOrientation =
      config[_Parameter.androidScreenOrientation] as String?;
  final brandingGravity =
      config[_Parameter.brandingGravity] as String? ?? 'bottom';
  final bool fullscreen = config[_Parameter.fullscreen] as bool? ?? false;
  final String iosContentMode =
      config[_Parameter.iosContentMode] as String? ?? 'center';
  final webImageMode = config[_Parameter.webImageMode] as String? ?? 'center';
  String? android12Image;
  String? android12DarkImage;
  String? android12IconBackgroundColor;
  String? darkAndroid12IconBackgroundColor;
  String? android12Color;
  String? android12DarkColor;
  String? android12BrandingImage;
  String? android12DarkBrandingImage;

  if (config[_Parameter.android12Section] != null) {
    final android12Config =
        config[_Parameter.android12Section] as Map<String, dynamic>;
    android12Image =
        _checkImageExists(config: android12Config, parameter: _Parameter.image);
    android12DarkImage = _checkImageExists(
        config: android12Config, parameter: _Parameter.darkImage);
    android12IconBackgroundColor =
        parseColor(android12Config[_Parameter.iconBackgroundColor]);
    darkAndroid12IconBackgroundColor =
        parseColor(android12Config[_Parameter.iconBackgroundColorDark]);
    android12Color = parseColor(android12Config[_Parameter.color]) ?? color;
    android12DarkColor =
        parseColor(android12Config[_Parameter.darkColor]) ?? darkColor;
    android12BrandingImage = _checkImageExists(
        config: android12Config, parameter: _Parameter.brandingImage);
    android12DarkBrandingImage = _checkImageExists(
        config: android12Config, parameter: _Parameter.brandingDarkImage);
  }

  if (!config.containsKey(_Parameter.android) ||
      config[_Parameter.android] as bool) {
    if (Directory('android').existsSync()) {
      _createAndroidSplash(
        imagePath: imageAndroid ?? image,
        darkImagePath: darkImageAndroid ?? darkImage,
        brandingImagePath: brandingImageAndroid ?? brandingImage,
        brandingDarkImagePath: brandingDarkImageAndroid ?? brandingDarkImage,
        backgroundImage: backgroundImageAndroid ?? backgroundImage,
        darkBackgroundImage: darkBackgroundImageAndroid ?? darkBackgroundImage,
        color: colorAndroid ?? color,
        darkColor: darkColorAndroid ?? darkColor,
        gravity: gravity,
        brandingGravity: brandingGravity,
        fullscreen: fullscreen,
        screenOrientation: androidScreenOrientation,
        android12ImagePath: android12Image,
        android12DarkImagePath: android12DarkImage ?? android12Image,
        android12BackgroundColor: android12Color,
        android12DarkBackgroundColor: android12DarkColor ?? android12Color,
        android12IconBackgroundColor: android12IconBackgroundColor,
        darkAndroid12IconBackgroundColor:
            darkAndroid12IconBackgroundColor ?? android12IconBackgroundColor,
        android12BrandingImagePath: android12BrandingImage,
        android12DarkBrandingImagePath:
            android12DarkBrandingImage ?? android12BrandingImage,
      );
    } else {
      print('Android folder not found, skipping Android splash update...');
    }
  }

  if (!config.containsKey(_Parameter.ios) || config[_Parameter.ios] as bool) {
    if (Directory('ios').existsSync()) {
      _createiOSSplash(
        imagePath: imageIos ?? image,
        darkImagePath: darkImageIos ?? darkImage,
        backgroundImage: backgroundImageIos ?? backgroundImage,
        darkBackgroundImage: darkBackgroundImageIos ?? darkBackgroundImage,
        brandingImagePath: brandingImageIos ?? brandingImage,
        brandingDarkImagePath: brandingDarkImageIos ?? brandingDarkImage,
        color: colorIos ?? color,
        darkColor: darkColorIos ?? darkColor,
        plistFiles: plistFiles,
        iosContentMode: iosContentMode,
        iosBrandingContentMode: brandingGravity,
        fullscreen: fullscreen,
      );
    } else {
      print('iOS folder not found, skipping iOS splash update...');
    }
  }

  if (!config.containsKey(_Parameter.harmony) ||
      config[_Parameter.harmony] as bool) {
    if (Directory('ohos').existsSync()) {
      _createHarmonySplash(
          imagePath: imageHarmony ?? image,
          darkImagePath: darkImageHarmony ?? darkImage,
          color: colorHarmony ?? color,
          darkColor: darkColorHarmony ?? darkColor,
          backgroundImage: backgroundImageHarmony ?? backgroundImage,
          darkBackgroundImage:
              darkBackgroundImageHarmony ?? darkBackgroundImage,
          harmonyModuleJsonFilePath:
              harmonyModuleJsonFile ?? 'ohos/entry/src/main/module.json5',
          harmonyIndexEtsFilePath:
              harmonyIndexEtsFile ?? 'ohos/entry/src/main/ets/pages/Index.ets');
    } else {
      print('Harmony folder not found, skipping harmony splash update...');
    }
  }

  if (!config.containsKey(_Parameter.web) || config[_Parameter.web] as bool) {
    if (Directory('web').existsSync()) {
      _createWebSplash(
        imagePath: imageWeb ?? image,
        darkImagePath: darkImageWeb ?? darkImage,
        backgroundImage: backgroundImageWeb ?? backgroundImage,
        darkBackgroundImage: darkBackgroundImageWeb ?? darkBackgroundImage,
        brandingImagePath: brandingImageWeb ?? brandingImage,
        brandingDarkImagePath: brandingDarkImageWeb ?? brandingDarkImage,
        color: colorWeb ?? color,
        darkColor: darkColorWeb ?? darkColor,
        imageMode: webImageMode,
        brandingMode: brandingGravity,
      );
    } else {
      print('Web folder not found, skipping web splash update...');
    }
  }

  const String greet = '''

βœ… Native splash complete.
Now go finish building something awesome! πŸ’ͺ You rock! 🀘🀩
Like the package? Please give it a πŸ‘ here: https://pub.flutter-io.cn/packages/flutter_native_splash
''';

  const String whatsNew = '''
╔════════════════════════════════════════════════════════════════════════════╗
β•‘                                 WHAT IS NEW:                               β•‘
╠════════════════════════════════════════════════════════════════════════════╣
β•‘ You can now keep the splash screen up while your app initializes!          β•‘
β•‘ No need for a secondary splash screen anymore. Just use the remove()       β•‘
β•‘ method to remove the splash screen after your initialization is complete.  β•‘
β•‘ Check the docs for more info.                                              β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
''';
  print(whatsNew + greet);
}