I know how you can set the initial state of a bloc easily. Is it possible to dispatch an event when a new bloc is created?
class MyBloc extends Bloc<MyEvent, MyState> {
MyBloc() :
this.dispatch(MyEvent()), // this line doesn't work
super();
@override
MyState get initialState => MyStateInitial();
@override
Stream<MyState> mapEventToState(MyEvent event) async* {
if (event is MyEvent) {
... do some stuff here ...
yield MyStateAfterMyEvent(someParameters, thatCantBe, setManually);
}
}
}
I know passing parameters to the bloc constructor could work sometimes. In my case parameters are fetched from the internet so I need more dynamic option. What is the way of achieving this?