appNameCahnge method
Implementation
Future<void> appNameCahnge(String newName) async {
if (!await File(PATH_MANIFEST).exists()) {
print(
'ERROR:: build.gradle file not found, Check if you have a correct android directory present in your project'
'\n\nrun " flutter create . " to regenerate missing files.');
return;
}
String? contents = await readFileAsString(PATH_MANIFEST);
final parsed = XmlDocument.parse(contents!);
final application = parsed.findAllElements("application").toList()[0];
final List<String> label = application.attributes
.where((attrib) => attrib.toString().contains("android:label"))
.map((i) => i.toString())
.toList();
if (label.isEmpty) {
throw Exception("Could not find android:label in $PATH_MANIFEST");
}
var neweContents =
contents!.replaceAll(label[0], 'android:label="$newName"');
print(neweContents);
await writeFileFromString(PATH_MANIFEST, neweContents);
print("CHANGE APP NAME");
}