Home > Software engineering >  how to do an auto increment of id inside of class?
how to do an auto increment of id inside of class?

Time:06-21

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. and the value f the integer must be an int which and the first value must be 0 and then it increment by one . i used

    class data {
        final String name = "test" ;
        final notificationId = UniqueKey().hashCode;

     }

but it gives random values and in my case i need values starts from 0 and increment by 1 .How to do it ? is there any others packages

CodePudding user response:

you can use Shared Preference to store last int value and increase it on next notification, i hope that will help you. If you are using local database to store notification, then create a column of int type with auto increments, and use that id to cancel that notification

For your reference read here about Shared Preference

  • Related