Flutter todo add list

Viewed 58

I'm new to Flutter and I'm making a todo app. I have used alertdialog in the application and I want to add a widget that can be managed with tiles in a list view with a button, just like in the picture, how can I do this?

enter image description here [enter image description here2

3 Answers

First, you need to save your data, for this, you can use localstorage.

https://pub.dev/packages/localstorage

You can create storage with this command.

final LocalStorage storage = new LocalStorage('todolist');

Then you can save todos to this storage.

saveToStorage() {
   storage.setItem('todos', list.toJSONEncodable());
}

You can use storage clear to delete all todos.

await storage.clear();

With this, you can now save Todos to your app. After this, you need to create a FutureBuilder, with this you can create TodoList. Something like this, you can change it to whatever you want.

FutureBuilder(
  future: storage.ready,
  builder: (BuildContext context, AsyncSnapshot snapshot) {
    List<Widget> widgets = list.items.map((item) {
      return CheckboxListTile(
        value: item.done,
        title: Text(item.title),
        selected: item.done,
        onChanged: (_) {
          _toggleItem(item);
        },
      );
    }).toList();});

In general, you have to have some kind of state management to pass the data and some kind of local or online data storage to save the data. I think this youtube video is good for you.

use below code in dialogbox

 showDialog<String>(
    context: context,
    builder: (BuildContext context) => AlertDialog(
      title: const Text('AlertDialog Title'),
      content: const Text('AlertDialog description'),
      actions: <Widget>[
        TextButton(
          onPressed: () => Navigator.pop(context, 'Cancel'),
          child: const Text('Cancel'),
        ),
        IconButton(
                  onPressed: (){},
                  icon: const Icon(Icons.save),)
      ],
    ),
  ),

make use of IconButton Widget to get save icon

Related