1

Screen code I am building a timesheet function on flutter where I get a list from JSON like this

[
  {
    "date": "2023-02-06 00:00:00.000",
    "startTime": "2023-02-06 07:00:00.000",
    "endTime": "2023-02-06 16:00:00.000"
  },
  {
    "date": "2023-02-07 00:00:00.000",
    "startTime": "2023-02-07 09:00:00.000",
    "endTime": "2023-02-07 19:00:00.000"
  },
  {
    "date": "2023-02-07 00:00:00.000",
    "startTime": "2023-02-07 10:00:00.000",
    "endTime": "2023-02-07 17:00:00.000"
  },
  {
    "date": "2023-02-08 00:00:00.000",
    "startTime": "2023-02-08 10:00:00.000",
    "endTime": "2023-02-08 17:00:00.000"
  },
  {
    "date": "2023-02-08 00:00:00.000",
    "startTime": "2023-02-08 03:00:00.000",
    "endTime": "2023-02-08 18:00:00.000"
  }
]

I am able to store it and display it on screen by simply pressing on the desired date (where the get timesheet function gets called), but the problem occurs when the user is trying to access a new week, the data does not load dynamically as there is preexisting data in the prefs, the only way to view a new week is by pressing the submit button, but that is not how it should work. I have tried using an if statement if the list is not empty but when i log out and back in it breaks and neither timesheets view anymore. Is there a way to make the prefs either A) add to the prefs the new data coming in when getTimeSheet is called, or B) simply replace the existing data with the new one. Please let me know

I tried doing

if( pref.getString('week_key') != null || pref.getString('week_key') != '') 

to load in the new data but that breaks upon exiting and re entering the application.

Luke B
  • 2,075
  • 2
  • 18
  • 26

0 Answers0