asString static method
Converts a list of strings to a formatted string.
Example: 'one', 'two', 'three'
-> 'one, two, and three'
Implementation
static String asString(List<String> list) {
String buffer = '';
if (list.isNotEmpty) {
int size = list.length;
int end = size - 1;
int and = size - 2;
for (int index = 0; index < size; index++) {
if (index == and) {
buffer = '$buffer${list[index]} and ';
} else if (index == end) {
buffer = '$buffer${list[index]}';
} else {
buffer = '$buffer${list[index]}, ';
}
}
}
return buffer;
}