changeIosLauncherIcon function
Change the iOS launcher icon
Implementation
Future<void> changeIosLauncherIcon(String iconName, String? flavor) async {
final File iOSConfigFile = File(iosConfigFile);
final List<String> lines = await iOSConfigFile.readAsLines();
bool onConfigurationSection = false;
String? currentConfig;
for (int x = 0; x < lines.length; x++) {
final String line = lines[x];
if (line.contains('/* Begin XCBuildConfiguration section */')) {
onConfigurationSection = true;
}
if (line.contains('/* End XCBuildConfiguration section */')) {
onConfigurationSection = false;
}
if (onConfigurationSection) {
final match = RegExp('.*/\\* (.*)\.xcconfig \\*/;').firstMatch(line);
if (match != null) {
currentConfig = match.group(1);
}
if (currentConfig != null &&
(flavor == null || currentConfig.contains('-$flavor')) &&
line.contains('ASSETCATALOG')) {
lines[x] = line.replaceAll(RegExp('\=(.*);'), '= $iconName;');
}
}
}
final String entireFile = '${lines.join('\n')}\n';
await iOSConfigFile.writeAsString(entireFile);
}