dart - 导航到其他页面

原文 标签 dart flutter

我在flutter应用程序中使用了一个日期选择器cupertino:

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');

关于dart - 导航到其他页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54281997/

相关文章:

flutter - 单击其他元素时触发可见性窗口小部件抖动

css - 如何更改 Material 标题行的颜色并使 Material 标题标题与App Layout的中心对齐?

json - 如何在 Dart 中使用 json_annotation 将 Uint8List 序列化为 json?

flutter - 在dispose()方法内部使用Provider.of(context)调用方法会导致 "Looking up a deactivated widget'的祖先不安全。”

flutter - 如何使用 Getx 在 Controller 层内检索 TextEditingController?

firebase - 在Firebase重设密码表单中自定义验证和文本?

dart - 如何在内置值枚举类中定义字段?

list - flutter Dart : how can I change the value of a class property in a list of Classes

http - 如何在flutter http put方法中传递带有body的参数

flutter - 单色,适用于所有背景页面