I am extremely new to Flutter, so please forgive my ignorance and please explain things to me like I am a toddler.

I would like to implement a to-do list into my app similar to this project: https://github.com/ishrath-raji/todoey-flutter

It's just a basic list where users can add items, cross them out, and delete them. Very simple.

However, I have absolutely no idea how to take the items that users enter into the to-do list and store them in memory so that the user can review them later.

I've tried googling around, but all the answers I've seen are above my understanding and/or written in a way that is difficult to follow.

Any help would be very much appreciated!


Solution 1: Andreas

I assume you have a view / page, where the user can give all the necessary information for the new ToDo item. This means you have a class representing a ToDoItem.

class ToDoItem {}

You will want to store them in some List.

As you probably want this list of ToDo items to be accessbible everywhere within the map, you should start researching the topic "state management".

As a starting point, just to name the easiest of all solutions, you could use Riverpod and declare one global variable:

final todoListRereference = StateProvider<List<ToDoItem>>((ref) => <ToDoItem>[]);

Now you have a list of ToDoItem which is accessible from everywhere in your app, provided you follow the steps to make Riverpod providers accessible everywhere. For example, in every build method you can use

final todoList = ref.watch(todoListRereference);

and you have access to all the stored ToDoItems.

In the case of your ToDoItem you can create with all the user information, you will have a construction like:

onPressed: () {
  final todoItem = ToDoItem(...);
  final todoListProvider = ref.read(todoListReference.notifier);
  todoListProvider.state = [... todoListProvider.state, todoItem);
}

I just assumed it would happen after the user clicked something and the onPressed method of the according button is triggered.... However, first you create the ToDoItem. Then you access the List we made accessible with the reference. Then we change the "state" of that provider to a new state which is defined as all the old ToDoItems plus the newly created one.

If you have any pages in your app where you can see all the ToDoItems, you will now see one more.

I hope this is okay as a starting point.