write method

Future<void> write(
  1. String path,
  2. String content, {
  3. FileMode mode = FileMode.write,
})

Implementation

Future<void> write(
  String path,
  String content, {
  FileMode mode = FileMode.write,
}) async {
  final file = File(path);
  final isExists = await file.exists();
  if (!isExists) {
    throw IOFailure(
      cause: "can't write in '$path' because this path is not exists",
    );
  }
  try {
    await file.writeAsString(content, mode: mode);
  } catch (e) {
    throw IOFailure(cause: e.toString());
  }
}