writeToFile method
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;
}
}