我正在尝试使用 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.dart
或 cupertino.dart
,具体取决于您选择的路线类型。
关于dart - 参数类型 '_PostCreateRoute' 无法分配给参数类型 'Route<Map>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54344212/