I'm trying to add flutter_bloc to my flutter application. I have Home page and when click on a button in home page Need to Navigation to a different page. Navigation is working without any issue, But When Wrap the the component with a BlocProvider getting below wrror
The argument type 'MyBloc' can't be assigned to the parameter type 'MyBloc Function(BuildContext)'
This what I have tried so far
My Bloc
import 'package:flutter_bloc/flutter_bloc.dart';
enum MyEvent {increment, decrement}
class MyBloc extends Bloc<MyEvent, int> {
MyBloc() : super(0);
@override
Stream<int> mapEventToState(MyEvent event) async* {
switch (event) {
case MyEvent.increment:
yield state + 1;
break;
case MyEvent.decrement:
yield state - 1;
break;
}
}
}
In home page I'm calling below function when click on button
Future<void> _routeToTodayTasks() {
return Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => BlocProvider<MyBloc>(
create: MyBloc(),
child: TodayTasks(),
)));
}
(context)=> MyBloc(),