0
Navigator.of(context).pushNamed('/placebids', arguments: {
  'ProductId': productDocumentId,
  'ProductName': productName,
});

I am passing this data to the new screen in flutter and i have to use it in the initState() method. Can anyone help how to do this.

Divyanshu Bhaskar
  • 335
  • 1
  • 4
  • 15

1 Answers1

1

In your case you can get back the data by using in the new screen:

final Map arguments = ModalRoute.of(context).settings.arguments as Map;

Then you will be able to get the productId by using:

arguments['ProductId']

It's the solution for recovering data, the way you pass it on.

Alternatively you can also use state management tools like MobX, Provider, ... which will allow you to simplify the sharing of variables between screens.

huextrat
  • 402
  • 3
  • 11