Search code examples
flutterunique-idflutter-local-notification

How to generate a Unique id, flutter


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.


Solution

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

    final notificationId = UniqueKey().hashCode()
    // or you can use DateTime.now().millisecondsSinceEpoch
    ...