writeToFile method

Future<bool> writeToFile(
  1. String filePath,
  2. String text, {
  3. dynamic sudo = false,
})

Write text to filePath If sudo is true, the file will be written with sudo permissions

Implementation

Future<bool> writeToFile(String filePath, String text, {sudo = false}) async {
  try {
    if (Platform.isWindows) {
      await File(filePath).writeAsString(text);
      return true;
    } else {
      List<String> args = ['-c', 'echo "$text" > $filePath'];
      final result = await simple('sh', args, sudo: sudo);
      return result.exitCode == 0;
    }
  } catch (e) {
    return false;
  }
}