I am making an application in which by selecting the ListView
I can send the data using the following method
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HimnoDetalle(todo: Himnoslista[index]),
),
);
},
But I have added one PopupMenuButton
which at the moment has 2 options, both buttons send to different interfaces I did it in the following way
trailing: PopupMenuButton<String>(
onSelected: _choiceAction,
itemBuilder: (BuildContext context) {
return Constants.choices.map((String choice) {
return PopupMenuItem<String>(
value: choice,
child: Text(choice),
);
}).toList();
},
)
where _choiceAction is a method within the same class declared as follows
void _choiceAction(String choice) {
if (choice == Constants.agregarPlay) {
Navigator.pushNamed(context, "/Play_List");
} else if (choice == Constants.agregarFavorit) {
Navigator.pushNamed(context, "/Registro");
}
}
But my intention is to send the name to the interface that you specify depending on the selection thePopupMenuButton
I tried to add the following method inside the PopupMenuButton
but it gives me errors... my Listview
complete is as follows
body: ListView.builder(
itemCount: Himnoslista.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(Himnoslista[index].tituloHimno),
// Cuando un usuario pulsa en el ListTile, navega al DetailScreen.
// Tenga en cuenta que no solo estamos creando un DetailScreen,
// también le pasamos el objeto Todo actual!
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HimnoDetalle(todo: Himnoslista[index]),
),
);
},
trailing: PopupMenuButton<String>(
onSelected: Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HimnoDetalle(todo: Himnoslista[index]),
),
),
itemBuilder: (BuildContext context) {
return Constants.choices.map((String choice) {
return PopupMenuItem<String>(
value: choice,
child: Text(choice),
);
}).toList();
},
),
);
But it gives me an error in the following lines that are where the selection of the element of thePopupMenuButton
onSelected: Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HimnoDetalle(todo: Himnoslista[index]),
),
),
The error is because the method
onSelected
expects a callBack String, not a StringFuture
that is returned by theNavigator.push
.Change this:
For this: