I have this widget:
body: CustomScrollView(
slivers: <Widget>[
SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return _team(context, index);
}, childCount: Provider.of<Game>(context).teams.list.length),
),
],
),
Here I displays an array of objects (or list of maps) with a int
property.
How can I order my array by this without modifying the variable itself?
You can take a local variable and randomise it by using the below function and can use it.
List shuffle(List items) {
var random = new Random();
// Go through all elements.
for (var i = items.length - 1; i > 0; i--) {
// Pick a pseudorandom number according to the list length
var n = random.nextInt(i + 1);
var temp = items[i];
items[i] = items[n];
items[n] = temp;
}
return items;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.