Search code examples
flutterdartuuid

How to generate an empty UUID in Dart


Currently, I use the "UUID package" (UUID 2.2.2) to generate a random UUID.

Uuid().v4().toString();   // -> 11c43ee8-b9d3-4e51-b73f-bd9dda66e29c

Some of our data have a reference to an empty guid (C#) instead of null. Is there a way to generate this empty guid or do I need to hardcode it somewhere for comparison reasons?

I expect this output for an empty UUID:

00000000-0000-0000-0000-000000000000

Solution

  • You can use the static Uuid class from that package and get this constant value.

    Uuid.NAMESPACE_NIL

    e.g.

    const empty = Uuid.NAMESPACE_NIL;