The argument type 'MaterialPageRoute<dynamic>' can't be assigned to the parameter type 'String'

Viewed 34

I am building a flutter app and I am trying to pass data to a page using MaterialPageRouter but I am getting an error that says "The argument type 'MaterialPageRoute dynamic' can't be assigned to the parameter type 'String'". Does anyone know what is this cause and please can anyone assist.

Here's the code that is causing the error

                          onTap: () {
                            Navigator.pushNamed(
                                context,
                                MaterialPageRoute(
                                    builder: (context) =>
                                        ProductDetails(
                                            id: bottleCategory.bottleList[index].id,
                                            bottleName: bottleCategory.bottleList[index].bottleName,
                                            image: bottleCategory.bottleList[index].image,
                                            price: bottleCategory.bottleList[index].price)));
                          },
2 Answers

You are passing a MaterialPageRoute hence you need to use Navigator.push, not the Navigator.pushNamed.

Navigator.pushNamed is for using named routes.

You have to use Navigator.push, not Navigator.pushNamed

Related