I wanted to add event when initializing bloc inside the 'main.dart'. But It didn't call init event . Are there any way to do this without calling inside 'initState' of the next class
void main() {
runApp(
MultiBlocProvider(providers: [
BlocProvider(create: (context) => CountlyBloc()..add(CountlyInitEvent()))
], child: MyApp()),
);
}
Solution 1: BHARATH T
Just set lazy
param inside the BlocProvider
as true. By default, the bloc is instantiated only when it is used first. Setting the lazy param to true, forces it to instantiate at the moment.
void main() {
runApp(
MultiBlocProvider(providers: [
BlocProvider(create: (context) => CountlyBloc()..add(CountlyInitEvent()),lazy:true,)
], child: MyApp()),
);
}
Hope it helps! Happy coding:)