Flutter MultiBlocProvider Performance


I have a MultiBlocProvider assigned for an app that has a Bottom Navigation Bar to navigate through main routes like Home, Search, Wishlist

I use setState(){} to change the currentPage for each route.

Recently I’ve added Blocs to each of them by using flutter_bloc package and I’m using BlocProvider to provide the bloc to each BlocBuilder,

  Widget build(BuildContext context) {
    return SafeArea(
      top: false,
      child: Scaffold(
        key: _scaffoldKey,
        body: PageStorage(
          child: Stack(
            children: <Widget>[
                duration: Duration(milliseconds: 200),
                  child: BlocProvider<WishlistBloc>(
                      create: (BuildContext context) => WishlistBloc(WishlistRepository()),
                      child: currentPage),
          bucket: bucket,

Is it ok to use MultiBlocProvider to provide all the BlocsProviders I need?

they could be more than 10 providers, would it affect the performance of the app?


It’s definitely OK, MultiBlocProvider created for this purposes. But you need to understand, that if you with your creation also send(for e.x.) initialize event which started loading in all 10 blocs some data you will have some issues. So, if you will have some performance issues, please create separate SO question and community will help to find root-cause of this.

Answered By – Yauhen Sampir

Answer Checked By – Marie Seifert (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *