Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
/// State is composed all the variables declared in the State implementation of a Stateful widget
class TodoListState extends State<TodoList> {
final List<Todo> todos = List<Todo>();
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Todo'),
body: Padding(
padding: EdgeInsets.all(16.0),
child: todos.length > 0
? ListView.builder(
itemCount: todos.length,
itemBuilder: _buildRow,
: Text('There is nothing here yet. Start by adding some Todos'),
/// build a single row of the list
Widget _buildRow(context, index) => Row(
children: <Widget>[
value: todos[index].completed,
onChanged: (value) => _changeTodo(index, value)),
style: TextStyle(
decoration: todos[index].completed
? TextDecoration.lineThrough
: null))
/// toggle the completed state of a todo item
_changeTodo(int index, bool value) =>
setState(() => todos[index].completed = value);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment