Reputation: 419
I'm trying to pass data from a screen with navigator.pop, it shows the result in the second screen, but in the first screen the data is always null. I tried some things on it but didn't work.
Here I'm calling the second screen:
onPressed: () async {
final result = await push(context, PickMaterialPage());
print("Result $result");
},
In this one is when I want to pass the data for the first screen with navigator.pop, It's an object.
Card card(int index, context) {
RequisicaoMaterial material = materiais[index];
try {
return Card(
color: Colors.grey[300],
elevation: 6.0,
margin: new EdgeInsets.symmetric(horizontal: 15.0, vertical: 10.0),
child: GestureDetector(
onTap: () => pop(context, material),
child: CustomListTile(
Icons.shopping_cart_outlined,
'${material.codMaterial} - ${material.nomeMaterial}',
'${material.codUnidade} - ${material.sigla} - ${material.classificacao}',
null,
),
));
} catch (e) {
print(e);
}
I don't want to use constructor in this one, i needed to make it simple and only get the picked data to show in the first screen.
output $result = null
Upvotes: 1
Views: 613
Reputation: 2503
Do it like this
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (_) => PickMaterialPage(),
)).then((value) => print(value)),
Upvotes: 1
Reputation: 4575
PUSH THE SCREEN
String result = await Navigator.push(
context,
MaterialPageRoute(
builder: (_) => AddTenantToRoomFlyPage(),
),
);
POP THE SCREEN
Navigator.pop(context, "RETURN VALUE");
Upvotes: 1