handleSource method

String handleSource(
  1. String? string,
  2. int errorLine
)

Implementation

String handleSource(String? string, int errorLine) {
  final lines = string?.split('\n') ?? [];
  final lines2 = [];

  int from = math.max(errorLine - 6, 0);
  int to = math.min(errorLine + 6, lines.length);

  for (int i = 0; i < lines.length; i++) {
    lines[i] = "${(i + 1)}: ${lines[i]}";
  }

  for (int i = from; i < to; i++) {
    lines2.add("${(i + 1)}: ${lines[i]}");
  }

  return lines2.join('\n');
}