[Solved] How to generate a Unique id, flutter

Question

Asked by Rohith N on December 30, 2021 (source).

I am making a todo app with notifications and am using flutter local notifications plugin, How do I generate a unique integer as id for a specific todo so that I can also cancel notification of that specific todo using that unique integer.

Answer

Question answered by DarShan (source).

You can use UniqueKey().hashCode() to get a unique int.
For example:

final notificationId = UniqueKey().hashCode()
// or you can use DateTime.now().millisecondsSinceEpoch
...
FLUTTER FLUTTER-LOCAL-NOTIFICATION UNIQUE-ID
SHARE: