Home > Net >  The argument type 'MaterialPageRoute<dynamic>' can't be assigned to the paramet
The argument type 'MaterialPageRoute<dynamic>' can't be assigned to the paramet

Time:09-17

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

CodePudding user response:

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

Navigator.pushNamed is for using named routes.

CodePudding user response:

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

  • Related