Anesu Mazvimavi
Anesu Mazvimavi

Reputation: 139

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

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

Upvotes: 3

Views: 592

Answers (2)

Ozan Taskiran
Ozan Taskiran

Reputation: 3552

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

Upvotes: 2

Tirth Patel
Tirth Patel

Reputation: 5736

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

Navigator.pushNamed is for using named routes.

Upvotes: 8

Related Questions