Skip to content

Commit

Permalink
fix(flutter_todos): use ListView.builder for improved performance (#…
Browse files Browse the repository at this point in the history
…4275)

Co-authored-by: Felix Angelov <[email protected]>
  • Loading branch information
jon-zuka and felangel authored Nov 16, 2024
1 parent 5d80dcc commit 5726a19
Showing 1 changed file with 26 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,31 +100,32 @@ class TodosOverviewView extends StatelessWidget {
}

return CupertinoScrollbar(
child: ListView(
children: [
for (final todo in state.filteredTodos)
TodoListTile(
todo: todo,
onToggleCompleted: (isCompleted) {
context.read<TodosOverviewBloc>().add(
TodosOverviewTodoCompletionToggled(
todo: todo,
isCompleted: isCompleted,
),
);
},
onDismissed: (_) {
context
.read<TodosOverviewBloc>()
.add(TodosOverviewTodoDeleted(todo));
},
onTap: () {
Navigator.of(context).push(
EditTodoPage.route(initialTodo: todo),
);
},
),
],
child: ListView.builder(
itemCount: state.filteredTodos.length,
itemBuilder: (_, index) {
final todo = state.filteredTodos.elementAt(index);
return TodoListTile(
todo: todo,
onToggleCompleted: (isCompleted) {
context.read<TodosOverviewBloc>().add(
TodosOverviewTodoCompletionToggled(
todo: todo,
isCompleted: isCompleted,
),
);
},
onDismissed: (_) {
context
.read<TodosOverviewBloc>()
.add(TodosOverviewTodoDeleted(todo));
},
onTap: () {
Navigator.of(context).push(
EditTodoPage.route(initialTodo: todo),
);
},
);
},
),
);
},
Expand Down

0 comments on commit 5726a19

Please sign in to comment.