Flutter MultiBlocProvider性能 [英] Flutter MultiBlocProvider Performance

查看:194
本文介绍了Flutter MultiBlocProvider性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为一个应用程序分配了 MultiBlocProvider ,该应用程序具有底部导航栏,可浏览诸如 Home Search之类的主要路线愿望清单 ...

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

我使用 setState(){} 更改每个路由的 currentPage .

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

最近,我通过使用 flutter_bloc 包向其中的每个添加了 Blocs ,并且我正在使用 BlocProvider 为每个组提供Bloc BlocBuilder

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,

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

可以使用 MultiBlocProvider 提供我需要的所有BlocsProvider吗?

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

他们可能有10个以上的提供商,这会影响应用程序的性能吗?

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

推荐答案

绝对可以,为此目的创建了MultiBlocProvider.但您需要了解,如果您在创建时还发送了(例如)初始化事件,该事件开始在所有10个区块中加载某些数据,那么您将遇到一些问题.因此,如果您遇到一些性能问题,请创建一个单独的SO问题,社区将帮助您找到根本原因.

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.

这篇关于Flutter MultiBlocProvider性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆