颤动多个集团和命名路线 [英] Flutter Multiple Blocs and NamedRoutes

查看:51
本文介绍了颤动多个集团和命名路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

寻找一些有关颤振架构的建议.我正在构建一个应用程序,该应用程序约有10个屏幕都存储为命名路由,并使用onGenerateRoute.

Looking for a bit of advice regarding some flutter architecture. I'm building an app that has about 10 screens all stored as named routes and using onGenerateRoute.

我正在尝试实现块和流,以便当另一页创建新记录(全部由在线SQL数据库处理)时可以广播到一页.

I'm trying to implement blocs and streams so that I can broadcast to one page when another page, say, creates a new record (all handled in an online SQL db).

因此,我有两个页面使用一个块,另外3个页面需要访问另一个块...等等.这是否意味着提供访问权限的唯一方法是将所有块的块提供者放在顶部小部件树,使所有集团可用于所有页面?

So I have two pages that use one bloc, another 3 pages that need access to another bloc... etc.. Does this mean that only way to provide access is to put a bloc provider for all blocs at the top of the widget tree, making all blocs available to all pages?

我试图通过使用两个页面顶部的提供程序分别在两个页面上提供对一个块的访问...但是,我想这实际上是在创建两个单独的BloC对象吗?而不是两个页面实际上都使用相同的页面.因此,当页面B创建新记录时,它不会调用页面A来重新加载...

I tried to provide access to one bloc individually on two pages by using a provider at the top of each of those two pages... however, I guess this means I am actually creating two separate BloC objects? rather than both pages actually using the same one. So when page B creates a new record, it is not calling page A to reload...

我不想让所有页面都访问所有BloC,但是这样做是将Bloc放在需要它的任何页面的单个祖先的地方的唯一方法吗?

I'd rather not have all pages accessing all BloCs, but is the only way to do it to put the Bloc in a place where it is a single ancestor of any page that needs it?

对于为什么关闭流,我也感到很困惑.我想指出的是,它们是连续的数据源...如果我们关闭它们,它们将不再可以广播给订户吗?

I'm also rather confused about why we close streams... I thought the point is that they are a continuous source of data... if we close them, are they no longer available to broadcast to subscribers?

一头雾水,过了三个小时的YouTube视频,我再也不清楚了.预先感谢...

Utterly confused, and 3 hours of YouTube videos later, I'm no clearer. Thanks in advance...

推荐答案

查看此内容在放置需要块的小部件时,也应该放置块.否则,保持活动状态会不必要地消耗资源.

When the Widgets that need the blocs are disposed, the blocs are also should be disposed. Otherwise you're consuming resources unnecessarily by keeping it alive.

这篇关于颤动多个集团和命名路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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