参数类型"_PostCreateRoute"不能分配给参数类型"路由<Map>"



我正在尝试使用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()作为参数传递给只接受Route()类型参数的push函数。

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

你可以试试这样的东西:

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

请确保根据使用的路由类型导入material.dartcupertino.dart

相关内容

最新更新