createMipmapXmlFile function

Future<void> createMipmapXmlFile(
  1. Config config,
  2. String? flavor
)

Implementation

Future<void> createMipmapXmlFile(
  Config config,
  String? flavor,
) async {
  // Note: Adaptive Icons will only be used when both
  // `adaptive_icon_background` and `adaptive_icon_foreground` or
  // `adaptive_icon_monochrome` are specified (The `image_path` is not
  // automatically taken as foreground)
  if (!config.hasAndroidAdaptiveConfig &&
      !config.hasAndroidAdaptiveMonochromeConfig) {
    return;
  }

  utils.printStatus('Creating mipmap xml file Android');

  String xmlContent = '';

  if (config.hasAndroidAdaptiveConfig) {
    if (isAdaptiveIconConfigPngFile(config.adaptiveIconBackground!)) {
      xmlContent +=
          '  <background android:drawable="@drawable/ic_launcher_background"/>\n';
    } else {
      xmlContent +=
          '  <background android:drawable="@color/ic_launcher_background"/>\n';
    }

    xmlContent += '''
  <foreground>
      <inset
          android:drawable="@drawable/ic_launcher_foreground"
          android:inset="${config.adaptiveIconForegroundInset}%" />
  </foreground>
''';
  }

  if (config.hasAndroidAdaptiveMonochromeConfig) {
    xmlContent += '''
  <monochrome>
      <inset
          android:drawable="@drawable/ic_launcher_monochrome"
          android:inset="${config.adaptiveIconForegroundInset}%" />
  </monochrome>
''';
  }

  late File mipmapXmlFile;
  if (config.isCustomAndroidFile) {
    mipmapXmlFile = File(
      constants.androidAdaptiveXmlFolder(flavor) + config.android + '.xml',
    );
  } else {
    mipmapXmlFile = File(
      constants.androidAdaptiveXmlFolder(flavor) +
          constants.androidDefaultIconName +
          '.xml',
    );
  }

  await mipmapXmlFile.create(recursive: true);
  await mipmapXmlFile.writeAsString(
    xml_template.mipmapXmlFile.replaceAll('{{CONTENT}}', xmlContent),
  );
}