1
votes

I am trying to make a social networking site using flutter . This is a feed related page which stores if there are feed available for the user or not and if there are feed it shows it . I am using asynchronous method for action during feed update so while creating on-pressed it is showing an error while creating PostCreateRoute object that the argument type '_PostCreateRoute' can't be assigned to the parameter type 'Route'. and I am new to flutter and if someone can help me out it would be great .

 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)
      } 
 }

}

1

1 Answers

0
votes

It looks like you are passing _PostCreateRoute() as an argument to the push function which only accepts the arguments of type Route().

You first need to wrap your class in a route object like MaterialPageRoute (Android) or CupertinoPageRoute (iOS).

You can try something like:

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

Make sure you import material.dart or cupertino.dart depending on which route type you go with.