readLines function

List readLines(
  1. String filePath
)

Implementation

List<dynamic> readLines(String filePath) {
  // check if the file exists
  if (File(filePath).existsSync() == false) {
    // return with empty list
    return <dynamic>[];
  }
  // As File exists, now start reading line by line.
  //
  // mapping lines to jsonDecode so as to convert `stringified` lines to `List<HashMap>`.
  final result =
      File(filePath).readAsLinesSync().map(jsonDecode).toList(growable: false);
  return result;
}