loadComments method

List<ReviewComment> loadComments()

Reads all stored comments from comments.json.

Implementation

List<ReviewComment> loadComments() {
  final file = File(commentsFilePath);
  if (!file.existsSync()) return <ReviewComment>[];

  try {
    final decoded = jsonDecode(file.readAsStringSync());
    if (decoded case {'comments': final List<Object?> rawComments}) {
      return [
        for (final item in rawComments)
          if (item is Map<String, Object?>)
            ReviewComment.fromJson(item)
          else if (item is Map)
            ReviewComment.fromJson(item.cast<String, Object?>()),
      ];
    }
  } on Exception {
    // Return empty list if file was empty or malformed.
  }
  return <ReviewComment>[];
}