safeEndSubstring method
Substring with safe end, so if end will be greater than length, it will not throw.
Start is not safe.
Implementation
String safeEndSubstring(int start, [int? end]) {
return substring(start, end == null ? null : math.min(end, length));
}