Created
June 25, 2020 12:32
-
-
Save velotiotech/aecd442c876eedd56d4ba0319e919adc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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>(); | |
@override | |
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>[ | |
Checkbox( | |
value: todos[index].completed, | |
onChanged: (value) => _changeTodo(index, value)), | |
Text(todos[index].label, | |
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