Where do you usually place your BlocProvider?
above the Scaffold?
I nside the body of the widget?
And why?
Where do you usually place your BlocProvider?
above the Scaffold?
I nside the body of the widget?
And why?
With BlocProvider, BlocBuilder, BlocConsumer you should place it above where it’s needed. You should avoid unnecessary rebuilds, and unnecessary tree traversal.
ok, i use it above the body just and if i have any changes in the appbar or floating action button
it will make the blocProvider above all scaffold so it will make any issues in performance or tree traversal ?
It depends on the features you are building. I typically believe there are 2 general use cases:
Best practice: don’t use BLOC at all (nor Riverpod).
I wouldn’t say it as extreme but it’s worth checking alternatives. And instead of a block provider many devs just register all blocs in get_it
Hi All,
I am a dot net developer with more than 10 years of experience. Now, I extended my skills in Flutter. I have been learning and working on Flutter since last year.
I would like to know from the experienced and experts of Flutter that which is the best state management technique and the satisfying justification.
Thanks in advance..
Hey, and welcome.
This is a bit like asking “tabs vs spaces… and cite your sources.” I think you’ll get a lot of varying perspectives.
Speaking from experience, I can say this:
flutter_bloc
.I also hear Riverpod is quite a nice solution, and some day I may check it out, but somebody else would have to weigh in on that solution.
Your next question is, “why flutter_bloc
?” That’s a fair question. For me, I like being able to separate my states from my events, and have my business logic be separated from both of those. I like having the clear distinction.
I highly recommend checking out watch_it because it’s one of the easiest and approachable state management solutions.
OK, a bit more context to the question why do so many people use bloc. I think it was kind of a misunderstanding bloc was originally designed inside google to share business logic between Angular Dart Web apps and Flutter app which is a requirement that is quite different from what most mobile apps need. But because it was presented by a member of the Flutter team, people thought it is the official recommendation from Google how to do state management. The @felangel published his very well made package and many devs just followed that path.
Currently we have three real alternatives IMHO that I would take into consideration for a bigger app:
Supported by Invoice Ninja and Event Schedule
It's All Widgets! • Flutter Pro • FlutterX • Flutter Streams • Flutter Podcast
Using contents of this forum for the purposes of training proprietary AI models is forbidden. Only if your AI model is free & open source, go ahead and scrape. Flutter and the related logo are trademarks of Google LLC. We are not endorsed by or affiliated with Google LLC.