dart - 导航到其他页面
问题描述
我在 Flutter 应用程序中使用了 Datepicker Cupertiono:
https://github.com/wuzhendev/flutter-cupertino-date-picker
有一个名为“onConfirm()”的方法,我试图将用户重定向到其他页面,但没有运气。我试过了
return Navigator.pushReplacementNamed(ctx, '/otherPage');
但是当这个返回语句被命中时,实际发生的是 cupertino 小部件关闭并且没有任何反应。没有错误
当我尝试使用:
return Navigator.pushNamed<bool>(
ctx,
'/route/' + object.id.toString());
出现一些错误:
Performing hot restart...
Restarted application in 1 685ms.
I/flutter (20542): 112
E/flutter (20542): [ERROR:flutter/shell/common/shell.cc(188)] Dart Error: Unhandled exception:
E/flutter (20542): Looking up a deactivated widget's ancestor is unsafe.
E/flutter (20542): At this point the state of the widget's element tree is no longer stable. To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling
inheritFromWidgetOfExactType() in the widget's didChangeDependencies() method.
E/flutter (20542):
E/flutter (20542): #0 Element._debugCheckStateIsActiveForAncestorLookup.<anonymous closure> (package:flutter/src/widgets/framework.dart:3232:9)
E/flutter (20542): #1 Element._debugCheckStateIsActiveForAncestorLookup (package:flutter/src/widgets/framework.dart:3241:6)
E/flutter (20542): #2 Element.ancestorStateOfType (package:flutter/src/widgets/framework.dart:3289:12)
E/flutter (20542): #3 Scaffold.of (package:flutter/src/material/scaffold.dart:935:42)
解决方案
你应该使用Navigator.push
. 导入您的页面,例如:import './otherPage.dart';
比改变你的线路
return Navigator.pushReplacementNamed(ctx, '/otherPage');
至
return Navigator.push(context, 'otherClassName');
推荐阅读
- python - 在 Windows 10 上更新 python 后 pip 安装问题
- ios - 组合:像 Future 一样的发布者,但具有多个值
- google-sheets - 如何根据两个不同列中的列中的值自动填充谷歌表格中的数据
- sql-server - SQL Server openjson
- c++ - 仅通过 C++ 中数组的不同初始化方法在相同的输入上获得两个不同的答案
- node.js - 如何保存我不明白 .save() 工作的猫鼬数据?
- c# - 在 Mongodb C# 中使用 AsQueryable 进行过滤 - ExpandoObject
- python - IndexError:列表索引超出范围(使用 python 的网络爬虫)
- javascript - 如何将初始值添加到 redux 表单单选按钮
- mysql - 如何托管 reactJs(frontend) NodeJs(backend) 和 Mysql 数据库