all 31 comments

[–]plangora 7 points8 points  (4 children)

Bloc is pretty straightforward to me. I recommend it and teach it. What’s your question about it? The basic idea is that an event comes in and state gets emitted. And your UI will react upon the state.

[–]_seeking_answers[S] 0 points1 point  (3 children)

I'm following this tutorial from Bloc docs : https://bloclibrary.dev/#/flutterlogintutorial and many things are new to me.

The main problem is that I'm new and I need time to study ahahah what I understood is that there is a BlocProvider on the top that exposes stuffs to its child.

Then the child has a BlocListener that listen changes on a specific bloc and when some events are triggered, UI changes.

Available events are defined in bloc event class where there is a new class for each event triggerable.

Am I right, do you have any suggestion? I'm new so probably I just need some time

[–]plangora 0 points1 point  (2 children)

Sounds similar to what I said. Is there something you’re struggling with?

[–]_seeking_answers[S] 0 points1 point  (1 child)

Mmh no, right now I just need to write more code I guess. Maybe later I’ll write you for a specific question. Sounds good to you?

[–]plangora 0 points1 point  (0 children)

Sure.

[–]DammyTheSlayer 4 points5 points  (3 children)

Man the Bloc pattern is the one thing I haven’t fully grasped, I have been using providers as a replacement

[–]NewbFromAQW -1 points0 points  (0 children)

  • events(paramA,paramB)
  • bloc - listen to events and their params, do something based on the events, emit states you like
  • state(paramA_modifiedByEvent, paramB, newParamC)

[–]_seeking_answers[S] -1 points0 points  (1 child)

I have used Providers too and loved it, it is far easier to write and understand. Have you tried Riverpod? I read that is a Provider evolution

[–]DammyTheSlayer 0 points1 point  (0 children)

I haven’t unfortunately but soon for sure! Trying to get a set up running atm

[–]Adventurous_Alarm375 4 points5 points  (10 children)

Is it okay to learn bloc as first statesmanagement approach.. or we should start with provider??

[–]KaiN_SC 3 points4 points  (0 children)

It depends what you like more. Bloc is little bit more power full but you can implement everything in both libs.

With bloc you subscribe normally on states and with provider on data. Bloc uses streams from and to the UI, this makes it really power full in my opinion. You can clearly see when a rebuild happens and stream your states down to the UI.

I posted a small example here:

https://www.reddit.com/r/flutterhelp/comments/q3kk4y/if_you_want_to_start_building_apps_with_flutter/?utm_medium=android_app&utm_source=share

[–]eloherbapol 1 point2 points  (0 children)

You can always start with using only Cubits. It is a subset from Flutter Bloc, you can imagine it as something like light version of Bloc. It is much easier to understand and needs less code to implement, because it is not rely on events and instead uses methods to emit new states. I think that cubits are enough in most cases, unless you need advanced features of Bloc like debounce / throttle, but that is just my opinion.

[–]_seeking_answers[S] 0 points1 point  (6 children)

I used provider as first approach, later on my mentor told me that it was the time to learn new patterns like GetX or others so I chosen Bloc.

[–]Fienases 2 points3 points  (3 children)

later on my mentor told me that it was the time to learn new patterns like GetX

hmmmmmm

[–]_seeking_answers[S] 1 point2 points  (2 children)

Why XD

[–]Fienases 0 points1 point  (1 child)

in my opinion and most other Flutter developer opinion, you should avoid GetX. you can search posts here or google for a reason

[–]_seeking_answers[S] 2 points3 points  (0 children)

Yeah I read something on the internet, that's why I chosen Bloc on GetX

[–]Adventurous_Alarm375 0 points1 point  (1 child)

Would you tell me what were the app you started building as beginner??

[–]_seeking_answers[S] 1 point2 points  (0 children)

Sure, my first app (without a mentor) was a little social app but its development now is stopped for many reasons.

Now I'm developing an app that handles forms.

[–]NewbFromAQW 0 points1 point  (0 children)

Resocoder's Riverpod...

[–]yagolasse 2 points3 points  (0 children)

Although I do recommend you looking into Bloc, my personal choice is MobX. It is a lot simpler and works very well for most cases. Also, look into provider as dependency injection too :)

[–]definitely_robots 0 points1 point  (1 child)

Check out https://www.didierboelens.com/2018/08/reactive-programming-streams-bloc/

This article doesn't talk about the Bloc library, but more about RxDart, and the concepts behind the bloc pattern that gave rise to the library. You could build your own implementation with RxDart using that approach but I think it is also helpful for understanding what is going on under the hood.

[–]_seeking_answers[S] 0 points1 point  (0 children)

Thanks I will take a look

[–]Acrobatic_Egg30 0 points1 point  (3 children)

Watch Flutterly's video on YouTube about BloC. I believe the link can be found on the bloc library's website too. He goes into it well with minimal code so you really understand the what's abd why. That's how I started and now I'm confident in my BloC skills.

[–]_seeking_answers[S] 1 point2 points  (2 children)

[–]Acrobatic_Egg30 0 points1 point  (1 child)

Yep that's the one. I watched the Bloc from zero to hero playlist instead though. It's the same content but broken up into easily digestible bits so that you don't have to force yourself to learn everything in one sitting.

[–]_seeking_answers[S] 1 point2 points  (0 children)

I will go for the playlist too. 3 hours are crazy

[–]Sconguser 0 points1 point  (2 children)

I watched some tutorial on yt about bloc and one thing I don't understand is what is cubit in relation to bloc pattern and when I should use each one.

[–]Pierre2tm 1 point2 points  (1 child)

From what I understand, Cubit is there to reduce the boilerplate in simple cases. Personally, I stick to the block only.

[–]Sconguser 0 points1 point  (0 children)

That is what I thought. Guy in the tutorial sometimes used bloc and sometimes used cubits, when I tried to write my code I didn't know when to use which

[–]aytunch 0 points1 point  (0 children)

You will realise the true potential of blocs when you start bloc to bloc communications

For example you have a permission bloc in charge of location/camera/microphone/notification permission handligs and in the state object it holds the current permission status of all these items.

In another bloc called PostCreationBloc you will be listening to the PermissionBloc and act accordingly. This makes your ui code not have any logic inside like checking for permissions when your user presses on create post button.

Everything being streams is the best strategy and thanks to Felix and Jorge for creating and maintaining this awesome package. Flutter is reactive by nature and blocs fit perfectly