init method

Future<File?> init({
  1. Map<String, String>? data,
})

Implementation

Future<File?> init({Map<String, String>? data}) async {
  try {
    final bool fileIsExists = _xmlFile!.existsSync();
    if (fileIsExists) {
      final content = _xmlFile!.readAsStringSync();
      if (content.isEmpty) {
        await updateFileContent(xmlFileContent);
      }

      _document = XmlDocument.parse(_xmlFile!.readAsStringSync());

      final XmlElement? resourcesElement = _document?.getElement('resources');
      if (resourcesElement == null) {
        await updateFileContent(xmlFileContent);
      }

      await _modifyStringTag(data ?? {});
      return _xmlFile;
    }
    await _xmlFile!.create(recursive: true);
    await updateFileContent(xmlFileContent);
    await init(data: data);
  } on XmlException {
    Logger logger = Logger.standard();
    logger.stdout("strings.xml wrong formatted");
  }
  return null;
}