Describe the bug
The app is a simple messenger, using firestore.
After setting the message event/state/bloc and also the repository that handles the message sending/fetching
I instantiated the repository in main()
however, the following error is returned:
'package:pingMe/bloc/bloc.dart': Failed assertion: line 12 pos 51: 'repository!=null': is not true.
I believe the solution is really straightforward, but I had a hard time to figure it out since I am new to this pattern.
Repository:

bloc:

main:

message event and state:


Many thanks in advance
Younes
Hi @ywaz 馃憢
Looks like you're not passing the repository to your bloc in your BlocProvider creation.
create: (context) => MessageBloc(repository: yourRepositoryInstance)
Hi @narcodico ,
Thank you for your reply.
I see your point, but in the main SS (that was incomplete in my first message) I am intiializing my MessageBloc in the initstate
and only used BlocBuilder, which dosn't contain bloc property anymore as you can see here:

If I use BlocProvider, is the instantiation of MessageBloc in the initstate no longer needed?
the blocprovider doesn't contain neither the bloc property as shown in the weather app example:
https://medium.com/flutter-community/weather-app-with-flutter-bloc-e24a7253340d
thank you in advance.
Younes
Please share a minimal github repo with your issue, your screenshots are incomplete.
I've open a PR with fixes and improved coding practices.
Your initial code wasn't working because you had at some point in one of the constructors {@required repository} instead of {@required this.repository} and also you had no BlocProvider<MessageBloc> to provide an instance of MessageBloc to your widget tree. The quickest fix would have been to specify in your BlocBuilder cubit: _msgBloc.
Most helpful comment
I've open a PR with fixes and improved coding practices.
Your initial code wasn't working because you had at some point in one of the constructors
{@required repository}instead of{@required this.repository}and also you had noBlocProvider<MessageBloc>to provide an instance ofMessageBlocto your widget tree. The quickest fix would have been to specify in yourBlocBuildercubit: _msgBloc.