I've changed my Navigator.push to Navigator.pushNamed
but I don't understand how to pass data and receive/use it. If we use Navigator.push
, we can just do this and call the constructor to use the data, but if we use Navigator.pushNamed
, it sends arguments.
Now, how to call/use these arguments?
in /surveyPage page how do i call the arguments? in /surveyPage i have constructor languageCode but since I use pushNamed I cannot put languageCode.
This is the widget that I want to receive the argument, I want to pass the argument to languageCode
class SurveyConsentPage extends StatefulWidget {
SurveyConsentPage({this.languageCode, Key key}) : super(key: key);
final String languageCode;
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SurveyConsentPage(
languageCode: 'id',
),
),
);
pushNamed
Navigator.of(context).pushNamed('/surveyPage', arguments: 'id');
routes
case '/surveyPage':
return MaterialPageRoute(builder: (context) => SurveyConsentPage());
break;