createIcons method

  1. @override
void createIcons(
  1. Map<String, dynamic> config,
  2. String? flavor
)
override

Create all icons for the current platform based on the contents of config and the flavor.

Implementation

@override
void createIcons(Map<String, dynamic> config, String? flavor) {
  final String filePath = config['image_path_ios'] ?? config['image_path'];
  final Image? image = decodeImage(File(filePath).readAsBytesSync());
  if (image == null)
    return;

  String iconName;
  final dynamic iosConfig = config['ios'];
  if (flavor != null) {
    final String catalogName = 'AppIcon-$flavor';
    printStatus('Building iOS launcher icon for $flavor');
    for (IconTemplate template in iosIcons) {
      _saveNewIcons(template, image, catalogName);
    }
    iconName = iosDefaultIconName;
    _changeIosLauncherIcon(catalogName, flavor);
    _modifyContentsFile(catalogName);
  } else if (iosConfig is String) {
    // If the IOS configuration is a string then the user has specified a new icon to be created
    // and for the old icon file to be kept
    final String newIconName = iosConfig;
    printStatus('Adding new iOS launcher icon');
    for (IconTemplate template in iosIcons) {
      _saveNewIcons(template, image, newIconName);
    }
    iconName = newIconName;
    _changeIosLauncherIcon(iconName, flavor);
    _modifyContentsFile(iconName);
  }
  // Otherwise the user wants the new icon to use the default icons name and
  // update config file to use it
  else {
    printStatus('Overwriting default iOS launcher icon with new icon');
    for (IconTemplate template in iosIcons) {
      _overwriteDefaultIcons(template, image);
    }
    iconName = iosDefaultIconName;
    _changeIosLauncherIcon('AppIcon', flavor);
  }
}