I’m using image_picker library to pick multiple images and using the uuid library to assign a unique uuid to each image. I have a line which is the following :
final String ImageUuid = _uuid.v4();
which is equipped to return uuid for a single image.
So,
I have to transform the above to take a List of uuid’s for every image that is picked.
So I did,
List<String> ImageUuid = _uuid.v4();
which rightfully gives an error of A Value of String cannot be assigned to List.
Here is my declaration for the above line :
static const Uuid _uuid = Uuid();
How do I obtain a list of uuid using the declaration above for subsequent usage ?
>Solution :
The uuid package itself shows an example on how to generate multiple UUIDs and add them to a Set here (on line 182).
final numToGenerate = 3 * 1000 * 1000;
final values = <String>{}; // set of strings
var generator = Uuid();
var numDuplicates = 0;
for (var i = 0; i < numToGenerate; i++) {
final uuid = generator.v4();
if (!values.contains(uuid)) {
values.add(uuid);
} else {
numDuplicates++;
}
}
You can then assign each element of the Set to your images.