Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Declare a List of Uuid's from the uuid package

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading