栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Flutter Navigator.of(context).pop与Navigator.pop(context)的区别

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Flutter Navigator.of(context).pop与Navigator.pop(context)的区别

Navigator.push(上下文,路由)vs Navigator.of(上下文).push(路由)

导航器用于管理应用程序的页面堆栈(路线)。将给定的路线推送到屏幕上(导航器)时,我们需要获取正确的导航器,然后进行推送。

Navigator.of(context).push(route)
拆分
.of(context)
以获取正确的Navigator和
.push(route)
Navigator.of(context)
具有可选参数,如果
rootNavigator
设置为true,则从最远的位置开始给出NavigatorState。

  static NavigatorState of(    BuildContext context, {    bool rootNavigator = false,    bool nullOk = false,  })

Navigator.push(context,route)
是静态方法,并且两者都同时执行。内部调用
Navigator.of(context).push(route)
。导航器最紧密地包围了给定的上下文。

static Future<T> push<T extends Object>(BuildContext context, Route<T> route) {    return Navigator.of(context).push(route);}

pop()
与相似
push()

当多个导航器嵌套在App中时。

showDialog(...)
方法创建的对话框路由被推送到根导航器。如果应用程序具有多个Navigator对象,则可能有必要调用
Navigator.of(context,rootNavigator: true).pop(result)
来关闭对话框,而不仅仅是
Navigator.pop(context, result)



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/391278.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号