Lesson 39: Todo App

Create a simple Todo list using ListView and StatefulWidget.


List todos = [];

TextField(
  controller: todoController,
  decoration: InputDecoration(labelText: 'New Todo'),
),
ElevatedButton(
  onPressed: () {
    setState(() {
      todos.add(todoController.text);
      todoController.clear();
    });
  },
  child: Text('Add'),
),
ListView.builder(
  itemCount: todos.length,
  itemBuilder: (context, index) => ListTile(
    title: Text(todos[index]),
  ),
)
    
Previous Next Lesson