dart random from list code example
Example 1: how to return a random number from a list in dart
import "dart:math";
void main() {
var list = ['a','b','c','d'];
var element = getRandomElement(list);
print(element);
}
T getRandomElement<T>(List<T> list) {
final random = new Random();
var i = random.nextInt(list.length);
return list[i];
}
Example 2: flutter random pick in list
var randomItem = (list..shuffle()).first;