bloc币

Navigation patterns for flutter are hard. And this is a scenario I stumbled upon and couldn’t find an agreed upon pattern to handle, so I made up one.

颤振的导航模式很困难。 这是我偶然发现的一个场景,找不到可以处理的商定模式,所以我组成了一个场景。

The scenario is this: You want to navigate to some “Views” of the app, and keep track of the current “View” for usage on some widget outside that view.

场景是这样的:您想要导航到应用程序的某些“视图”,并跟踪当前“视图”以在该视图之外的某些小部件上使用。

In my case, it was the BottomNavigatonVar that needs to constantly have its currentIndex parameter updated to the correct menu item we are viewing.

就我而言,正是BottomNavigatonVar需要不断将其currentIndex参数更新为我们正在查看的正确菜单项。

To solve this, we have 3 issues to tackle:

为了解决这个问题,我们要解决3个问题:

  1. Set a central place for the currentView state.

    currentView状态设置一个中心位置。

  2. Update the currentView state whenever navigating to a new “View”.

    导航到新的“视图”时,请更新currentView状态。

  3. Update the currentView state whenever user hit “back” (Which is not active navigation, as the widget will not rebuild).

    每当用户单击“后退”时将更新currentView状态(这不是活动的导航,因为小部件将不会重建)。

国家管理 (State management)

For a central place for the state, I chose to use BLoC provider, that will wrap my entire application.

对于州的中心位置,我选择使用BLoC提供程序,它将包装我的整个应用程序。

As changing the currentView state will probably happen all around the app, we need something better than simple StatefulWidget . I chose BLoC, but really, Provider, RXDart or whatever is your favorite state management will work.

由于更改currentView状态可能会在整个应用程序中发生,因此我们需要比简单的StatefulWidget更好的东西。 我选择了BLoC,但实际上, ProviderRXDart或您最喜欢的状态管理都可以。

导航到新的“视图”时更新状态 (Updating state when navigating to new “View”)

In my opinion the routing functions are the best place to update the currentView state. That way, you guarantee to have it happen when a routing is actively occurring.

在我看来,路由功能是更新currentView状态的最佳位置。 这样,您可以保证在路由活动中积极进行路由。

Updating the state in other places, for example, when the “View” widget is building, is prone to bugs as the widget might rebuild even without new routing occurring.

在其他地方更新状态,例如在构建“视图”窗口小部件时,很容易出现错误,因为即使没有发生新的路由,窗口小部件也可能会重建。

用户返回时的更新状态(导航弹出窗口) (Updating state when user goes back (navigation pop))

We need to “go back” a state whenever the user hits “back”. For that we will use the WillPopScope widget wrapping our app. Using onWillPop parameter to update the state accordingly.

每当用户点击“返回”时,我们都需要“返回”状态。 为此,我们将使用包装我们的应用程序的WillPopScope小部件。 使用onWillPop参数来相应地更新状态。

历史数据结构 (Data structure for the history)

We want to keep track of the history as a whole, for pushing new routes and being able to pop and go back to old routes state.

我们希望跟踪整个历史,以便推动新路线并能够弹出并返回到旧路线状态。

That calls for a stack. Unsurprisingly, if you will look at Navigator implementation you’ll see they use _historystack (implemented through List) internally exactly for this purpose.

那需要堆栈。 毫不奇怪,如果您看一下Navigator实现,您会发现它们完全在内部使用_history堆栈(通过List实现)来实现此目的。

Our implementation will be similar, but limited to our scope. Instead of logging all route changes, we will log only those we care about and in format easy for us.

我们的实现将类似,但仅限于我们的范围。 除了记录所有路线更改之外,我们仅记录我们关心的内容并以易于使用的格式记录。

给我看代码 (Show me the code)

集团集团 (The bloc class)

Several things to address here:

这里要解决的几件事:

  • The event enum is an enum that list the possible routes and additional special event go_back that speaks for itself.

    事件枚举是一个枚举,它列出了可能的路线以及说明自己的其他特殊事件go_back

  • Having this enum separated from the routes code itself is an advantage, as it allows more flexibility for whatever usage you need. For example, having multiple app routes map to a single “View” enum.将此枚举与路由代码本身分开是一个优点,因为它可以为您所需的任何用法提供更大的灵活性。 例如,具有多个应用程序路线映射到单个“视图”枚举。
  • The event handling is pretty basic for readability. But this is the place to add code that will reject adding what is already the current route to the history, if that’s something you need.对于可读性而言,事件处理是非常基本的。 但这是添加代码的地方,如果需要的话,该代码将拒绝添加到历史记录的当前路径。

路由到新路线 (Routing to a new route)

Within the routing, we want to issue a bloc event for the appropriate view. that will look like this:

在路由中,我们要为适当的视图发出bloc事件。 看起来像这样:

BlocProvider.of<CurrentViewBloc>(context).add(ViewOptions.home);

Say you are using fluro for navigation in your app, that means having this as the first step of the handlerFunc. Like this:

假设您在应用程序中使用fluro进行导航,这意味着将其作为handlerFunc的第一步。 像这样:

初始化块,路由返回处理 (Initializing the bloc, routing back handling)

We need to initialize the bloc state, and coincidentally here I also take care of the route pop case.

我们需要初始化bloc状态,巧合的是,在这里我还要注意route pop的情况。

This should wrap the part of the app that is relevant for this routing. It can be on top of the entire application if your case necessitates that.

这应该包装与该路由相关的应用程序部分。 如果您的情况需要,它可以位于整个应用程序的顶部。

Thats it.

而已。

Pretty basic, but there are some tricks here that are nice to have in one place — using onWillPop , replicate a local history stack (I spent some time thinking Navigation reveals something like that, and that would have been a better way. But they don’t, _history is private) etc’ etc’.Hope it has been useful for you.

很简单,但是这里有一些技巧很不错,可以使用一个地方-使用onWillPop ,复制本地历史记录堆栈(我花了一些时间认为Navigation显示类似的东西,这本来是更好的方法。 't, _history是私有的)等'等'。希望它对您很有用。

翻译自: https://medium.com/flutter-community/flutter-app-navigation-state-and-menu-pattern-using-bloc-d5a42be941b2

bloc币


http://www.taodudu.cc/news/show-7077945.html

相关文章:

  • 币车上线100天,未来项目社区的践行者,继续起航
  • 【HIT-计算机系统】ICS-Lab2 DataLab
  • Codeforces ~ 996A ~ Hit the Lottery (贪心)
  • 【社区治理】币车社区规范V1.0版本
  • HIT Online Judge1006 - Weird Clock
  • python 最小硬币数_最小硬币数量的动态规划
  • 硬币组合问题python_关于硬币的python问题
  • 4G网关BL100链接私有云平台教程
  • H3C WA4320无线fit AP瘦模式转fat 胖模式 + 配置wifi上线
  • Photoshop学习(三十四):调整图像的某种颜色
  • 字体相关基础
  • 绿色创意2.0 探访阿里千岛湖数据中心
  • 两百家电视台上云端 传统电视自我救赎
  • 聚英国际|【燎原计划启动周第三期AMA】大陆节点数据中心揭秘!
  • 电视台成阿里云下一个大数据重塑目标
  • 老鱼看会:2017甲骨文云大会都说了些什么?
  • 阿里云推出国内首个社保云系统
  • 甲骨文全面升级云平台,赋能云端新企业
  • 阿里云千岛湖数据中心启用:自然城市与人文科技的完美结合
  • 安卓和ios移动端实现H5页面进行强制刷新
  • uniapp 下拉刷新、上拉加载更多、最常见的节流场景
  • HTML5+——APP实现热更新
  • 做Vue项目时点击按钮页面会刷新问题
  • #uni-app 开发项目实战# 下拉刷新,上拉加载数据
  • Uni-app实战上加载新下拉刷新
  • 乾坤:微应用非首次加载,需刷新才会重新加载
  • jquerymobile局部渲染的各种刷新
  • 移动端如何实现上拉加载?下拉刷新?
  • uni-app下拉刷新触底加载更多
  • iOS 11 MJ刷新异常,上拉加载出现跳动刷新问题

bloc币_使用bloc扑动应用程序的导航状态和菜单模式相关推荐

  1. 企业微信_新建自建H5小程序应用及主页与菜单设置

    文章目录 一.新建自建H5小程序应用 1. 登录企微管控台 2. 登录登录手机企微 3. 应用管理 4. 创建应用 5. 效果图 二.主页与菜单设置 2.1. 应用主页 2.2. 菜单设置 2.3. ...

  2. 渐进式web应用程序_如何使用渐进式Web应用程序更快,更便宜地构建新应用程序...

    渐进式web应用程序 You need an app! The question is- which kind? 您需要一个应用程序! 问题是--哪种? For the last 8 years or ...

  3. 比特币系列——竞争币、竞争块链和应⽤程序

    探讨⽐特币和区块链的发明的衍⽣物:2009年⽐特币诞⽣以来所涌现出来的竞争币.竞争块链和应⽤程序.将要探讨竞争币(alt coin),这些电⼦货币有着与⽐特币相似的的构建模式出来的,但它们完全独⽴地运 ...

  4. c语言程序设计实验指导交大答案,C语言程序设计实验指导_上交大_课前练习-改错-完善程序-课后练习参考答案--2018.10修改.doc...

    C语言程序设计实验指导_上交大_课前练习-改错-完善程序-课后练习参考答案--2018.10修改.doc 实验一 Visual C集成环境实验内容(一)程序改错1.(1)无法运行(2)将第二个C程序重 ...

  5. windows界面-python-运动倒计时程序

    windows-python-运动倒计时程序 程序中使用到的部分库的使用方法会在之后的文章中更新 程序预览 涉及的库 tkinter win32 win32.lib xlrd == 1.2.01 其中 ...

  6. 陈力:传智播客古代 珍宝币 泡泡龙游戏开发第43讲:PHP程序设计中的MVC模式

    陈力:传智播客古代 珍宝币 泡泡龙游戏开发第43讲:PHP程序设计中的MVC模式 模型(M)-视图(V)-控制器(C)mvc是一种软件设计模式,通过MVC思想进行实例开发和程序设计.     在前面的 ...

  7. 【写文章 奖C币 换好礼】文章上 “程序人生”,拿着C 币换好礼!

    各位童鞋们,小编每天会在CSDN社区选1到2篇精彩原创文章在微信公众号"程序人生"(微信号:coder_life)进行推送.不是技术文章,是与程序猿(媛)工作.生活相关的奇闻趣事哦 ...

  8. 怎样参与火箭计划币_从目的到计划不是火箭科学

    怎样参与火箭计划币 Purpose, mission, principles, vision, strategy, plan. The world is full of fuzzy words, ov ...

  9. react 组件连动效果_记一个缓动水柱React动画组件的初次尝试

    写完意识到这是第一篇,算是前言吧... 以后在zhihu写点东西...就当是博客好了,个人观点和体会而已,不求高大上,但求回头看的时候能够让以后的自己瞧不起. 背景:写React也一年多了,从一开始的 ...

最新文章

  1. R语言splines包构建基于logistic回归的自然样条分析:南非心脏病数据集、非线性:基函数展开和样条分析、你简单分析的不重要特征,可能只是线性不显著、而非线性是显著的
  2. Argparse简易教程
  3. Spring-Cloud中的统一配置中心
  4. python3爬虫(6)爬虫代理的使用
  5. MAC 下的简单 SHELL 入门
  6. 二分+树的直径 [Sdoi2011]消防
  7. LeetCode-438. 找到字符串中所有字母异位词
  8. Cilium架构:提供并透明地保护应用程序工作负载之间的网络连接和负载平衡
  9. git 刷新远程分支列表_掌握Git命令一张脑图就行
  10. 【数据结构】线性表之数组---C++语言描述
  11. Web安全攻防渗透测试实战指南笔记 三
  12. 特斯拉造芯片:不能失去集成电路的高地,就像西方不能失去耶路撒冷
  13. Office系列软件之间不兼容以及office修复
  14. Inpaint 强大的去水印、改图软体,轻鬆把不要的物件从相片中移除
  15. 计算机水平cet2是什么等级,英语cet2等级考试试题
  16. 心理学的应用领域有哪些?
  17. ubantu20.04安装PCL
  18. 最简单的加密---异或加密
  19. 怎么在一张图片中隐藏文件?
  20. 华盛顿大学 计算机专业排名,圣路易斯华盛顿大学计算机专业世界排名好不好?...

热门文章

  1. 数据库技术的发展历史是怎么样的?
  2. 纯真IP查询(转自:阿不)
  3. c语言怎么学自学,怎么学自学C语言啊?
  4. Python实现线性拟合
  5. 2020北大新生共4326人,强基录取占比近20%,竞赛破格考生309人
  6. CAS单点登录-单用户登录(十九)
  7. 为汽车新零售注入活力,瓜子二手车严选直卖店落地长沙
  8. 一套添加背景音乐视频教程,跟你分享添加背景音乐的软件
  9. Gnocchi: 1、Gnocchi源码分析
  10. 在petalinux下提示:Failed to menu config project component....