Why my state is not updating even if everything is okay?
class TodoPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
body: BlocBuilder<TodoBloc, TodoState>(
builder: (context, state) {
final bloc = context.read<TodoBloc>();
if (state is InitTodoState) {
if (state.todoList == null) return Offstage();
if (state.todoList!.isEmpty) {
return Center(child: Text('No todos available'));
}
return ListWidget();
} else {
return Loading(); // Show loading indicator
}
},
),
floatingActionButton: FloatingActionButton(
onPressed: () async {
await init(context);
},
),
),
);
}
Future<void> init(BuildContext context) async {
final getTodoListUseCase = GetTodoListUseCase(
firebaseTodo: TodoRepositoryImpl(FirebaseApiImpl()),
serverTodo: TodoRepositoryImpl(LocalApiImpl(RestApiImpl())),
);
var params;
final res = await getTodoListUseCase.call(params);
res.fold((failure) {
print("Failed to fetch todo list");
}, (todoList) {
print("Fetched todo list with ${todoList.length} items");
context.read<TodoBloc>().add(InitEvent(todoList));
});
}
}
while updating the bloc even if iam passing a new state then also I am not updating state the bloc is correctly iinitialize and the data is also comming I am not undetstanding why becouse if I change the routing way s comming but its not way to correct code practice how to do it?
New contributor
Jaydeep Wagh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.