reasonLine function
The line of detail that carries the reason: a VM header like "Unhandled exception:" is joined to the line after it, capped at 240 chars.
Implementation
String reasonLine(String detail) {
final lines = detail.split('\n').map((l) => l.trim()).where((l) => l.isNotEmpty).toList();
if (lines.isEmpty) return '';
var line = lines.first;
if (line.endsWith(':') && lines.length > 1) line = '$line ${lines[1]}';
return line.length > 240 ? '${line.substring(0, 239)}…' : line;
}