updateIosInfoPlist method

void updateIosInfoPlist(
  1. String iosConfiguration
)

Implementation

void updateIosInfoPlist(String iosConfiguration) async {
  // read the file
  final File iOSInfoPlistFile = File(_iOSInfoPlistFileName);
  final List<String> lines = await iOSInfoPlistFile.readAsLines();

  // iterate
  int arrayDictDepth = 0;
  bool inSkippedLines = false;
  List<String> newLines = [];
  for (int x = 0; x < lines.length; x++) {
    // get
    String line = lines[x];

    // count depth
    if (line.contains('<array>') || line.contains('<dict>')) {
      arrayDictDepth++;
    }
    if (line.contains('</array>') || line.contains('</dict>')) {
      if (--arrayDictDepth == 0) {
        inSkippedLines = false;
      }
    }

    // now do we need to skip
    if (line.contains('<key>') && arrayDictDepth == 1) {
      //print('Stop skipping because of $line');
      inSkippedLines = false;
    }
    if (line.contains('CFBundleDocumentTypes') ||
        line.contains('UTExportedTypeDeclarations') ||
        line.contains('LSSupportsOpeningDocumentsInPlace')) {
      //print('Start skipping because of $line');
      inSkippedLines = true;
    }

    // end of dict
    if (line.contains('</plist>')) {
      newLines.insertAll(newLines.length - 1, iosConfiguration.split('\n'));
    }

    // done
    if (inSkippedLines == false && line.trim().length > 0) {
      newLines.add(line);
    }
  }

  // update
  iOSInfoPlistFile.writeAsString(newLines.join('\n'));
  print('Android Manifest updated ($_iOSInfoPlistFileName)');
}