I want to mix a list that contains maps like this:
initTask() async {
List tasks = await ourDb.rawQuery("SELECT * FROM level1");
Random random = Random();
tasks.shuffle(random);
}
and then I got this error:
E/flutter (15953): [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception:
E/flutter (15953): Unsupported operation: read-only
can anyone help?
A Map is an object that maps keys to values or is a collection of attribute-value pairs. The list is an ordered collection of objects and the List can contain duplicate values. The Map has two values (a key and value), while a List only has one value (an element). So we can generate two lists as listed: List of keys from a Map.
The map () function (which is a built-in function in Python) is used to apply a function to each item in an iterable (like a Python list or dictionary). It returns a new iterable (a map object) that you can use in other parts of your code.
In React, we can use the map () function to map a list of values to a list of components. Let’s see how we can create a list in react using a simple project.
A map () is one such function that is used to create a list of objects by calling a function on each element of the array. In React, we can use the map () function to map a list of values to a list of components.
Even if you've solved your issue there is no accepted answers so I'm gonna try explaining the solution that was provided in the comment by pskink.
Usually data returned by a DB are immutable so by doing List tasks = await ourDb.rawQuery("SELECT * FROM level1");
you are getting an unmodifiable list reference. To be able to modify it you need to create a new list object from your original list.
You can either use List.of
or List.from
to generate a new modifiable list object containing all the items from your query.
List tasks = List.from(await ourDb.rawQuery("SELECT * FROM level1"));
List tasks = List.of(await ourDb.rawQuery("SELECT * FROM level1"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With