addLineToInfoPlist static method
void
addLineToInfoPlist(
{ - required String key,
- String? value,
- bool autoClose = false,
})
Implementation
static void addLineToInfoPlist(
{required String key, String? value, bool autoClose = false}) {
final file = File('ios/Runner/Info.plist');
final xml = XmlDocument.parse(file.readAsStringSync());
final root = xml.rootElement;
final dict = root.findElements("dict").first;
final elementKey = XmlElement(XmlName('key'), [], [XmlText(key)]);
final elementValue = autoClose
? XmlElement(XmlName('false'), [], [])
: XmlElement(XmlName('string'), [], [XmlText(value!)]);
int position = dict.children.indexOf(dict.findElements("key").firstWhere(
(element) => element.innerText == "UILaunchStoryboardName"));
dict.children.insert(position, elementValue);
dict.children.insert(position, elementKey);
final prettyXml = xml.toXmlString(pretty: true);
file.writeAsStringSync(prettyXml);
}