【问题标题】:Flutter MultiBlocProvider PerformanceFlutter MultiBlocProvider 性能
【发布时间】:2020-06-15 01:19:46
【问题描述】:

我有一个MultiBlocProvider 分配给一个应用程序,该应用程序有一个底部导航栏,可以在主页搜索等主要路线中导航, 愿望清单 ...

我使用setState(){} 为每条路线更改currentPage

最近我通过使用flutter_bloc 包为每个人添加了Blocs,并且我正在使用BlocProvider 为每个BlocBuilder 提供bloc,

 @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 提供我需要的所有 BlocsProviders 吗?

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

【问题讨论】:

    标签: android performance flutter bloc flutter-bloc


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-06
      • 1970-01-01
      • 2022-10-19
      • 2021-08-04
      • 1970-01-01
      • 1970-01-01
      • 2020-10-06
      • 2020-04-06
      相关资源
      最近更新 更多