How to convert String to Time in Hour, Minute, Second as integer in flutter? How to convert String to Time in Hour, Minute, Second as integer in flutter? flutter flutter

How to convert String to Time in Hour, Minute, Second as integer in flutter?


var splited = notifyTime.split(':');int hour = int.parse(splited[0]);int minute = int.parse(splited[1]);int second = int.parse(splited[2]);


You can do pattern splitting like in the answer by Jorge Vieira or you save yourself the parsing logic and just store it as ints.


For setting you can use setInt()

prefs.setInt("H",time.hours);prefs.setInt("m",time.minutes);prefs.setInt("s",time.seconds);

For getting it you can use getInt()

int hours = prefs.getInt("H");int mins = prefs.getInt("m");int secs = prefs.getInt("s");

Then from your methods just return the Time object

return Time(hours,mins,secs);