renameConfigsAppInfoValues method
Future<void>
renameConfigsAppInfoValues(
)
Implementation
Future<void> renameConfigsAppInfoValues() async {
List<DarwinBundleIDSettings> bundleIdSettings = getBundleIDSettings();
String product_bundle_id = bundleIdSettings.isNotEmpty ? bundleIdSettings.first.bundleId : "";
final filterList = bundleIdSettings.where((element) => element.buildType == kBuildTypeRelease).toList();
if (filterList.isNotEmpty) {
product_bundle_id = filterList.first.bundleId;
}
final map = {
'PRODUCT_NAME': bundleDisplayName,
'PRODUCT_BUNDLE_IDENTIFIER': product_bundle_id,
'PRODUCT_COPYRIGHT': copyright,
};
if (map.values.every((value) => value.isEmpty)) {
log("$platform $targetName, All values are empty, skipping...");
return;
}
try {
final file = File('$currentDirPath/${platform.name}/$targetName/Configs/AppInfo.xcconfig');
if (!file.existsSync()) {
logSkipping("$platform $targetName, Configs/AppInfo.xcconfig does not exist at ${file.path}");
return;
}
String content = file.readAsStringSync();
bool updated = false;
map.forEach((key, newValue) {
if (newValue.isNotEmpty) {
final newContent = content.replaceAllMapped(
RegExp('(^$key\\s*=\\s*).*\$', multiLine: true),
(match) => '${match.group(1)}$newValue',
);
if (newContent != content) {
content = newContent;
updated = true;
log("$platform $targetName, Updated $key = $newValue");
}
} else {
log("$platform $targetName, Skipping empty value for $key");
}
});
if (updated) {
file.writeAsStringSync(content, flush: true);
log("$platform $targetName, Configs/AppInfo.xcconfig updated successfully");
} else {
log("$platform $targetName, No changes needed in Configs/AppInfo.xcconfig");
}
} catch (e) {
log("$platform $targetName, error updating Configs/AppInfo.xcconfig: $e");
}
}