How can i use SharedPreferences with ListTile widget?

My Project

Hello and welcome!
Could you elaborate more on what you want to accomplish? It’s really hard to figure it out with so little context.

Hello. I want to keep every task of this app. They should be shown when app restart. I researched it and i understand to use SharedPreferences. Only one data shown with SharedPreferences of many examples.

In my opinion a sqlite database would fit better your use case.
SharedPreferences are intended for persisting simple data, in an unrelated way.
In your project you have two resources: Todos composed of lists of Tasks.
The Todo lists could be multiple, with a proper title maybe, each with its own task list.

Persisting those related data is the perfect job for a sqlite database with a very simple schema: two tables, todos and tasks, in a one-to-many relationship, where
a todos record has many tasks records, and each task record belongs to one todo record.

todos table

  • id: integer, primary key
  • title: text

tasks table

  • id: integer, primary-key
  • todo_id: integer, foreign-key
  • title: text
  • detail: text

If you are new to relational databases, you could also simplify the schema.
Just have a single unique todo list (and you can even use SharedPreferences to store its title) with many tasks. In this case you will not need the todos table at all, and the tasks table could be simplified omitting the todo_id foreign-key.

The following cookbook page gives you all the information you need to accomplish the second -simpler- scenario (one todo list as a single tasks table, no relationships)


1 Like