dart - 参数类型 '_PostCreateRoute' 无法分配给参数类型 'Route<Map>

标签 dart flutter

我正在尝试使用 flutter 制作一个社交网站。这是一个与提要相关的页面,它存储是否有可供用户使用的提要,如果有提要则显示它。我在提要更新期间使用异步方法进行操作,因此在创建按下时它在创建 PostCreateRoute 对象时显示错误,即参数类型“_PostCreateRoute”无法分配给参数类型“Route”。我是新手,如果有人能帮助我,那就太好了。

 class _FeedActionButtonState extends State<FeedActionButton> {
 BuildContext _context;

 @override
 Widget build(BuildContext context) {
    _context = context;
    return new FloatingActionButton(
    child: new Icon(Icons.add, color:Theme.of(context).iconTheme.color),
    onPressed: onPressed,
    backgroundColor: Colors.white);
 }
    onPressed() async{
    Mappost=await
    Navigator.of(_context).push(new_PostCreateRoute(_context));
    if (post!=null &&widget.onPosted!=null){
        this .widget.onPosted(post)
      } 
 }

最佳答案

看起来您正在将 _PostCreateRoute() 作为参数传递给 push 函数,该函数只接受 Route() 类型的参数。

您首先需要将您的类包装在一个路由对象中,例如 MaterialPageRoute (Android)CupertinoPageRoute (iOS)

你可以试试这样的:

Navigator.push(_context, MaterialPageRoute(builder: (BuildContext _context) => _PostCreateRoute(_context)));

确保导入 material.dartcupertino.dart,具体取决于您选择的路线类型。

关于dart - 参数类型 '_PostCreateRoute' 无法分配给参数类型 'Route<Map>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54344212/

相关文章:

javascript - 我应该在 Dart 映射键中使用 int/enum 或 String 来最大限度地减少内存使用吗?

java - 使用真实设备在Flutter中调试第一个应用程序时出错

flutter - 使用 super.key 和 (Key? key) : super(key: key) in flutter 有什么区别

dart - 很难在 flutter 中实现圆角模态底板

flutter - 调用 setState 时键盘关闭

firebase - 在构建时,StreamBuilder被多次调用

flutter - 验证器将 TextFormField 推送到上面

flutter - 如何在 Flutter 中正确绑定(bind)有状态小部件中的回调函数?

arrays - 需要将 JSON 数据提取字段配置到 flutter 中的小部件元素

Flutter Firestore 集合组