Bloc: The recommended way of using flutter bloc

Created on 9 Jun 2020  路  7Comments  路  Source: felangel/bloc

Here I want to ask what is better not issue really!

I have been searching different state managements in flutter and I lastly decided to go with flutter bloc
but when I read the articles and watch some tutorials I got different ways of using this bloc for example some people just create one bloc file and use streams for streaming and sinking events and data while others create three files 1 for events, 1 for states and one for the bloc to map events to states and no use of streams . The question is which way is preferred for bloc pattern?

question

Most helpful comment

@EngAddow in more recent versions flutter_bloc exports bloc which is why the bloc dependency is not critical but it's good to have in my opinion because it makes things more explicit.

All 7 comments

Hi @EngAddow 馃憢

The first way you're mentioning is actually the vanilla bloc which is different from flutter_bloc approach (second way) which was built to deal with the downsides of vanilla bloc.

I'd recommend you start by reading through docs. You could also check out the examples.

Hope that clears things out for you 馃憤

Hi @EngAddow 馃憢

The first way you're mentioning is actually the vanilla bloc which is different from flutter_bloc approach (second way) which was built to deal with the downsides of vanilla bloc.

I'd recommend you start by reading through docs. You could also check out the examples.

Hope that clears things out for you 馃憤

Thank you very much, I am reading the docs now and I got it says wee need two dependencies
dependencies: bloc: ^4.0.0 flutter_bloc: ^4.0.0
but in my case I just installed
dependencies: flutter_bloc: ^4.0.0

and everything is working fine for now
so what is the difference?

It's working because flutter_bloc depends on bloc so flutter will take care of making it available.

@EngAddow in more recent versions flutter_bloc exports bloc which is why the bloc dependency is not critical but it's good to have in my opinion because it makes things more explicit.

Closing for now but feel free to comment if you have any additional questions and I鈥檓 happy to continue the conversation 馃憤

Thank you very much I hope you make tutorials of real apps using flutter bloc.

@EngAddow in more recent versions flutter_bloc exports bloc which is why the bloc dependency is not critical but it's good to have in my opinion because it makes things more explicit.

I will insha Allah

Was this page helpful?
0 / 5 - 0 ratings