readFile function

Future<String?> readFile(
  1. String path, {
  2. bool throwExceptionIfExist = false,
})

Implementation

Future<String?> readFile(String path, {bool throwExceptionIfExist = false}) async {
  try {
    final Directory directory = Directory.current;
    final File file = File('${directory.path}/$path');
    String content = await file.readAsString();
    return content;
  } catch (e) {
    if (throwExceptionIfExist) rethrow;
    return null;
  }
}