I am sending back arguments using Navigator.pop by wrapping them in a class. But in previous screen printing the results say "Instance of 'FilterArguments' " var result = await Navigator.pushNamed(context, '/filters'); and send back data like this. Navigator.pop(context, FilterArguments(upperRange: 1000, lowerRange: 200, beds: 21));


Solution 1: Francisco Javier Snchez

Hellow Anas,

Welcome to stackoverflow, I see that you are also relativelly new to flutter also!

When sending back arguments in Navigator.pop(context, arguments) you can do multiple things. Sending back a custom Class is my way to go (as you have already done) so that is great.

However, when you try to print a class, you will always get the Instance of 'Something'. This is the correct behaviour, and it means that you got what you sent back.

If you want to check what is inside that class, I suggest putting a breakpoint and debug to it, however I can assure you that you got your data!

Edit with examples

class Fruit {
  final String name;
  final Color color;
  Fruit({this.name, this.color});
}

//Popping the info
...
Navigator.pop(context, Fruit(name: 'banana', color: Colors.yellow));
...

//Retreiving the info
...
final Fruit selectedFruit = await Navigator.pushNamed(context, '/fruit-selector');

//Using the info
print(selectedFruit.name);