For simple navigation with arguments from WidgetA to WidgetB
- Define routes in MaterialApp main widget:
return MaterialApp(
routes: {
'/routeAB': (context) => WidgetB(),
},
- In WidgetA use pushNamed method to navigate to WidgetB:
onTap: () {
Navigator.pushNamed(context, '/routeAB',
arguments: {
'arg1': val1,
'arg2': val2,
...
- Get arguments in WidgetB:
Map args = ModalRoute.of(context).settings.arguments;