createMipmapXmlFile function
Implementation
Future<void> createMipmapXmlFile(
Config config,
String? flavor, {
required FLILogger logger,
String prefixPath = '.',
}) async {
final String iconBaseName = config.isCustomAndroidFile
? config.androidIconName
: constants.androidDefaultIconName;
final File mipmapXmlFile = File(
path.join(
prefixPath,
constants.androidAdaptiveXmlFolder(flavor),
'$iconBaseName.xml',
),
);
// If the flavor already ships an adaptive-icon XML, edit its background color
// in place rather than overwriting it from the template — that preserves any
// authored `<shape>`/`<foreground>`/`<monochrome>` the user hand-wrote.
// existsSync is intentional: a single bool probe before deciding edit-vs-create.
if (mipmapXmlFile.existsSync()) {
await _editExistingAdaptiveBackground(
config,
mipmapXmlFile,
flavor,
logger: logger,
prefixPath: prefixPath,
);
return;
}
// 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;
}
logger.info('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>
''';
}
await mipmapXmlFile.create(recursive: true);
await mipmapXmlFile.writeAsString(
xml_template.mipmapXmlFile.replaceAll('{{CONTENT}}', xmlContent),
);
}