how to generate unique id in a simple way using flutter

There is a really simple and fast way of generating unique id's in flutter.

To do so we will use a light package called uuid, here for official repository

Let's add this package to our project inside the pubspec.yaml

  uuid: ^2.2.0

To add under the dependencies packages installed.

Now we can import it where needed, instanciate it and call a method.

import 'package:uuid/uuid.dart';

var uuid = Uuid();

// Generate a v4 (random) id
uuid.v4(); // -> '110ec58a-a0f2-4ac4-8393-c866d813b8d1'

For more details about this package you can check the official page linked up.

dart flutter ios android uuid