title: Flutter pass argument directly with named routes navigation
body: <p>I have been looking at all the answers on here to pass arguments when doing named route navigation but they seem to be old answers or they don't work.</p>
  
  <p>From what was written it should be working but it doesn't seem to do anything, so I am not sure where my error is.</p>
  
  <p>This is how I have it setup:</p>
  
  <p><strong>Main.dart</strong> (With my named routes setup):</p>
  
  <pre><code>  void main() =&gt; runApp(MyApp());
  
  class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            primaryColor: Colors.white,
          ),
          initialRoute: HomePageScreen.id,
          routes: {
            HomePageScreen.id: (context) =&gt; HomePageScreen(),
            AddItemScreen.id: (context) =&gt; AddItemScreen(),
            AdvertiseScreen.id: (context) =&gt; AdvertiseScreen(),
            HomePageFilterScreen.id: (context) =&gt; HomePageFilterScreen(),
            HomePageResultsScreen.id: (context) =&gt; HomePageResultsScreen(),
            ItemPageProfileScreen.id: (context) =&gt; ItemPageProfileScreen(),
            ItemPageProfileSuggestUpdateScreen.id: (context) =&gt; ItemPageProfileSuggestUpdateScreen(),
            ItemPageWhereToBuyAddStoreToDatabaseScreen.id: (context) =&gt; ItemPageWhereToBuyAddStoreToDatabaseScreen(),
            ItemPageWhereToBuyMapScreen.id: (context) =&gt; ItemPageWhereToBuyMapScreen(),
            ItemPageWhereToBuyScreen.id: (context) =&gt; ItemPageWhereToBuyScreen(),
            MenuScreen.id: (context) =&gt; MenuScreen(),
            NotAvailableScreen.id: (context) =&gt; NotAvailableScreen(),
            TermsScreen.id: (context) =&gt; TermsScreen(),
            }
     );
    }
  }
  </code></pre>
  
  <p><strong>HomePageResultsScreen.dart</strong> (On button click I am using push named to navigate to the next page, this is working because the new page 'ItemPageProfileScreen is opening):</p>
  
  <pre><code>onTap: () {
             Navigator.pushNamed(context, ItemPageProfileScreen.id, arguments: 'MyTestString');
            }
  </code></pre>
  
  <p><strong>ItemPageProfileScreen.dart</strong> (I have tried using MaterialApp onGenerateRoute to get the arguments and print to screen to test but it is not working):</p>
  
  <pre><code>  class ItemPageProfileScreen extends StatefulWidget {
  
    static const String id = 'item_page_profile_screen';
  
    @override
    _ItemPageProfileScreenState createState() =&gt; _ItemPageProfileScreenState();
  }
  
  class _ItemPageProfileScreenState extends State&lt;ItemPageProfileScreen&gt; {
    @override
    Widget build(BuildContext context) {
  
      MaterialApp(
        onGenerateRoute: (routeSettings){
          final arguments = routeSettings.arguments;
          print(arguments.toString());
        },
      );
  
      return Scaffold(),
  </code></pre>
  
  <p>Thanks for your help.</p>
  
  <p><strong>EDIT Second attempt:</strong></p>
  
  <pre><code>class ItemPageProfileScreen extends StatefulWidget {
  
    final String argument;
  
    ItemPageProfileScreen(this.argument);
  
    static const String id = 'item_page_profile_screen';
  
    @override
    _ItemPageProfileScreenState createState() =&gt; _ItemPageProfileScreenState();
  }
  
  class _ItemPageProfileScreenState extends State&lt;ItemPageProfileScreen&gt; {
    @override
    Widget build(BuildContext context) {
  
      return Scaffold(
        body: SingleChildScrollView(
          child: Column(
            children: &lt;Widget&gt;[
              Text(widget.argument),
  </code></pre>