How can I retrieve a random element from a collection in Dart?
var list = [\'a\',\'b\',\'c\',\'d\',\'e\'];
This works too:
var list = ['a','b','c','d','e'];
//this actually changes the order of all of the elements in the list
//randomly, then returns the first element of the new list
var randomItem = (list..shuffle()).first;
or if you don't want to mess the list, create a copy:
var randomItem = (list.toList()..shuffle()).first;