In the ToDo tutorial of BlocLibrary I cam along the following snippet.
TodosOverviewState copyWith({
TodosOverviewStatus Function()? status,
List<Todo> Function()? todos,
TodosViewFilter Function()? filter,
Todo? Function()? lastDeletedTodo,
}) {
return TodosOverviewState(
status: status != null ? status() : this.status,
todos: todos != null ? todos() : this.todos,
filter: filter != null ? filter() : this.filter,
lastDeletedTodo:
lastDeletedTodo != null ? lastDeletedTodo() : this.lastDeletedTodo,
);
}
What does this exactly do, how does it work? I know the copyWith but I don't get the .. Function()? ... part.
I found one more reference with Google where it was stated that it helps overcoming a null issue. But why do I need Function and what happens otherwise?
========================
UPDATE: I am not asking what copyWith is good for, only why they are using Function()? to copy a state and a simpler construct to copy a data object. The tutorial can be found here. There you will find the Function in the bloc code in "ToDosOverview" and the simpler one in the ToDoModel in "LocalStorageTodosApi"