limitString method
Limits the display string's length to width by removing the centre
components of the string and replacing them with '...'
Example: var long = 'http://www.onepub.dev/some/long/url'; print(limitString(long, width: 20))
http://...ong/url
Implementation
String limitString(String display, {int width = 40}) {
if (display.length <= width) {
return display;
}
final elipses = width <= 2 ? 1 : 3;
final partLength = (width - elipses) ~/ 2;
return '''
${display.substring(0, partLength)}${'.' * elipses}${display.substring(display.length - partLength)}''';
}