Pass arguments in Navigator push Named route

41- Flutter Pass arguments to a named route - YouTube 

For simple navigation with arguments from WidgetA to WidgetB

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

Post a Comment

Previous Post Next Post

Subscribe Us


Get tutorials, Flutter news and other exclusive content delivered to your inbox. Join 1000+ growth-oriented Flutter developers subscribed to the newsletter

100% value, 0% spam. Unsubscribe anytime