How do I pass non-string data to a named route in Flutter?












21















I have many screens, and I'm using the Navigator. I'd like to use "named routes", but I also need to pass non-string (such as images) to my next route.



I can't use pushNamed() because I can't pass non-string data to it.



How can I use a named route + send non-string data?










share|improve this question





























    21















    I have many screens, and I'm using the Navigator. I'd like to use "named routes", but I also need to pass non-string (such as images) to my next route.



    I can't use pushNamed() because I can't pass non-string data to it.



    How can I use a named route + send non-string data?










    share|improve this question



























      21












      21








      21


      9






      I have many screens, and I'm using the Navigator. I'd like to use "named routes", but I also need to pass non-string (such as images) to my next route.



      I can't use pushNamed() because I can't pass non-string data to it.



      How can I use a named route + send non-string data?










      share|improve this question
















      I have many screens, and I'm using the Navigator. I'd like to use "named routes", but I also need to pass non-string (such as images) to my next route.



      I can't use pushNamed() because I can't pass non-string data to it.



      How can I use a named route + send non-string data?







      dart flutter






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 5 at 13:39









      CopsOnRoad

      4,64022126




      4,64022126










      asked Nov 21 '17 at 18:11









      Seth LaddSeth Ladd

      28.6k17107199




      28.6k17107199
























          5 Answers
          5






          active

          oldest

          votes


















          28














          EDIT:



          It is now possible to pass complex arguments to Navigator.pushNamed:



          String id;
          Navigator.pushNamed(context, '/users', arguments: id);


          It can then be used within onGenerateRoute to customize route building with these arguments:



          MaterialApp(
          title: 'Flutter Hooks Gallery',
          onGenerateRoute: (settings) {
          final arguments = settings.arguments;
          switch (settings.name) {
          case '/users':
          if (arguments is String) {
          // the details page for one specific user
          return UserDetails(arguments);
          }
          else {
          // a route showing the list of all users
          return UserList();
          }
          default:
          return null;
          }
          },
          );





          share|improve this answer


























          • When the route is /myRoute/${myID} the path split has 3 items in the list with first being empty string "". Perhaps we have to ignore the path[0] and make use of path[1] and path[2]?

            – Gogu
            Nov 29 '17 at 18:59











          • I'd remove the first '/' in the route instead. But this is just an example, you're free to use whatever you want to.

            – Rémi Rousselet
            Nov 29 '17 at 19:02






          • 2





            Is the above answer still valid? I cannot see arguments property available via RouteSettings...

            – Angel Todorov
            Feb 5 at 16:35






          • 1





            It has been added very recently. You may want to switch of channel.

            – Rémi Rousselet
            Feb 5 at 17:57






          • 1





            Here is pull request for this feature: github.com/flutter/flutter/pull/27058

            – Michał Powłoka
            Feb 19 at 18:30



















          1














          For the outcome of this problem, I developed the package



          link: https://pub.dartlang.org/packages/navigate



          That provide to much your expect and easy to use



          Navigate.navigate(context,
          "home",
          transactionType:TransactionType.fromLeft , // optional
          replaceRoute: ReplaceRoute.thisOne, //optional
          arg: {"transactionType":TransactionType.fromLeft,"replaceRoute":ReplaceRoute.thisOne} //optional
          );





          share|improve this answer





















          • 1





            You should mention you are the author of that package.

            – Duncan Jones
            Dec 26 '18 at 9:20



















          0














          I am capturing images with camera then passing them through to a confirmation page like so:



             ImagePicker.pickImage(source: source).then((File file) {
          Navigator.push(
          context,
          MaterialPageRoute(
          builder: (context) => MediaCaptured(file: file),
          ));
          });


          You could easily do the same with any type of file or non-string data.



          var foo = "non-string data";
          Navigator.push(
          context,
          MaterialPageRoute(
          builder: (context) => MediaCaptured(foo: foo),
          ));


          Call the next page in the route by it's class name, as above.



          Just make sure your new page accepts this in it's constructor.



           // Stateful Widget
          class MediaCaptured extends StatefulWidget {
          MediaCaptured({ Key key, @required this.foo,}) : super(key: key);
          final var foo;
          }

          // StatelessWidget
          class MediaCaptured extends StatelessWidget {
          MediaCaptured(this.foo);
          var foo;
          }





          share|improve this answer































            0














            The Flutter Cookbook shows how to navigate to a new page and pass non-string data to it.



            Passing data to next page



            I started with Navigator.pushedNamed() because it was simple and I didn't have any data to pass. When my needs changed and I wanted to pass data, I switched to Navigator.push().



            Example:



            var nextPageData = {foo:'bar'};

            Navigator.push(
            context,
            MaterialPageRoute(builder: (context) =>
            MyNextPage(myData: nextPageData))
            );





            share|improve this answer































              -4














              We can pass any type of arguments when declaring routes as constructor arguments as below,

              For example to send a list of Strings,

              List<String> titles = ;

              void main() => runApp(
              new MaterialApp(
              home: new FirstPage(),
              routes: <String, WidgetBuilder>{
              "/SecondPage": (BuildContext context) => new SecondPage(titles),
              },
              ),
              );

              class FirstPage extends StatelessWidget {
              @override
              Widget build(BuildContext context) {
              return new Container(
              child: new RaisedButton(onPressed: () {
              Navigator.of(context).pushNamed('/SecondPage');
              }),
              );
              }
              }

              class SecondPage extends StatelessWidget {
              final List<String> titles;

              SecondPage(this.titles);

              @override
              Widget build(BuildContext context) {
              return new ListView.builder(
              itemBuilder: (context, index) {
              return new ListTile(
              title: new Text(titles[index]),
              );
              },
              );
              }
              }





              share|improve this answer























                Your Answer






                StackExchange.ifUsing("editor", function () {
                StackExchange.using("externalEditor", function () {
                StackExchange.using("snippets", function () {
                StackExchange.snippets.init();
                });
                });
                }, "code-snippets");

                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "1"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47419908%2fhow-do-i-pass-non-string-data-to-a-named-route-in-flutter%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                5 Answers
                5






                active

                oldest

                votes








                5 Answers
                5






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                28














                EDIT:



                It is now possible to pass complex arguments to Navigator.pushNamed:



                String id;
                Navigator.pushNamed(context, '/users', arguments: id);


                It can then be used within onGenerateRoute to customize route building with these arguments:



                MaterialApp(
                title: 'Flutter Hooks Gallery',
                onGenerateRoute: (settings) {
                final arguments = settings.arguments;
                switch (settings.name) {
                case '/users':
                if (arguments is String) {
                // the details page for one specific user
                return UserDetails(arguments);
                }
                else {
                // a route showing the list of all users
                return UserList();
                }
                default:
                return null;
                }
                },
                );





                share|improve this answer


























                • When the route is /myRoute/${myID} the path split has 3 items in the list with first being empty string "". Perhaps we have to ignore the path[0] and make use of path[1] and path[2]?

                  – Gogu
                  Nov 29 '17 at 18:59











                • I'd remove the first '/' in the route instead. But this is just an example, you're free to use whatever you want to.

                  – Rémi Rousselet
                  Nov 29 '17 at 19:02






                • 2





                  Is the above answer still valid? I cannot see arguments property available via RouteSettings...

                  – Angel Todorov
                  Feb 5 at 16:35






                • 1





                  It has been added very recently. You may want to switch of channel.

                  – Rémi Rousselet
                  Feb 5 at 17:57






                • 1





                  Here is pull request for this feature: github.com/flutter/flutter/pull/27058

                  – Michał Powłoka
                  Feb 19 at 18:30
















                28














                EDIT:



                It is now possible to pass complex arguments to Navigator.pushNamed:



                String id;
                Navigator.pushNamed(context, '/users', arguments: id);


                It can then be used within onGenerateRoute to customize route building with these arguments:



                MaterialApp(
                title: 'Flutter Hooks Gallery',
                onGenerateRoute: (settings) {
                final arguments = settings.arguments;
                switch (settings.name) {
                case '/users':
                if (arguments is String) {
                // the details page for one specific user
                return UserDetails(arguments);
                }
                else {
                // a route showing the list of all users
                return UserList();
                }
                default:
                return null;
                }
                },
                );





                share|improve this answer


























                • When the route is /myRoute/${myID} the path split has 3 items in the list with first being empty string "". Perhaps we have to ignore the path[0] and make use of path[1] and path[2]?

                  – Gogu
                  Nov 29 '17 at 18:59











                • I'd remove the first '/' in the route instead. But this is just an example, you're free to use whatever you want to.

                  – Rémi Rousselet
                  Nov 29 '17 at 19:02






                • 2





                  Is the above answer still valid? I cannot see arguments property available via RouteSettings...

                  – Angel Todorov
                  Feb 5 at 16:35






                • 1





                  It has been added very recently. You may want to switch of channel.

                  – Rémi Rousselet
                  Feb 5 at 17:57






                • 1





                  Here is pull request for this feature: github.com/flutter/flutter/pull/27058

                  – Michał Powłoka
                  Feb 19 at 18:30














                28












                28








                28







                EDIT:



                It is now possible to pass complex arguments to Navigator.pushNamed:



                String id;
                Navigator.pushNamed(context, '/users', arguments: id);


                It can then be used within onGenerateRoute to customize route building with these arguments:



                MaterialApp(
                title: 'Flutter Hooks Gallery',
                onGenerateRoute: (settings) {
                final arguments = settings.arguments;
                switch (settings.name) {
                case '/users':
                if (arguments is String) {
                // the details page for one specific user
                return UserDetails(arguments);
                }
                else {
                // a route showing the list of all users
                return UserList();
                }
                default:
                return null;
                }
                },
                );





                share|improve this answer















                EDIT:



                It is now possible to pass complex arguments to Navigator.pushNamed:



                String id;
                Navigator.pushNamed(context, '/users', arguments: id);


                It can then be used within onGenerateRoute to customize route building with these arguments:



                MaterialApp(
                title: 'Flutter Hooks Gallery',
                onGenerateRoute: (settings) {
                final arguments = settings.arguments;
                switch (settings.name) {
                case '/users':
                if (arguments is String) {
                // the details page for one specific user
                return UserDetails(arguments);
                }
                else {
                // a route showing the list of all users
                return UserList();
                }
                default:
                return null;
                }
                },
                );






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Jan 30 at 14:11

























                answered Nov 21 '17 at 18:55









                Rémi RousseletRémi Rousselet

                34.2k380105




                34.2k380105













                • When the route is /myRoute/${myID} the path split has 3 items in the list with first being empty string "". Perhaps we have to ignore the path[0] and make use of path[1] and path[2]?

                  – Gogu
                  Nov 29 '17 at 18:59











                • I'd remove the first '/' in the route instead. But this is just an example, you're free to use whatever you want to.

                  – Rémi Rousselet
                  Nov 29 '17 at 19:02






                • 2





                  Is the above answer still valid? I cannot see arguments property available via RouteSettings...

                  – Angel Todorov
                  Feb 5 at 16:35






                • 1





                  It has been added very recently. You may want to switch of channel.

                  – Rémi Rousselet
                  Feb 5 at 17:57






                • 1





                  Here is pull request for this feature: github.com/flutter/flutter/pull/27058

                  – Michał Powłoka
                  Feb 19 at 18:30



















                • When the route is /myRoute/${myID} the path split has 3 items in the list with first being empty string "". Perhaps we have to ignore the path[0] and make use of path[1] and path[2]?

                  – Gogu
                  Nov 29 '17 at 18:59











                • I'd remove the first '/' in the route instead. But this is just an example, you're free to use whatever you want to.

                  – Rémi Rousselet
                  Nov 29 '17 at 19:02






                • 2





                  Is the above answer still valid? I cannot see arguments property available via RouteSettings...

                  – Angel Todorov
                  Feb 5 at 16:35






                • 1





                  It has been added very recently. You may want to switch of channel.

                  – Rémi Rousselet
                  Feb 5 at 17:57






                • 1





                  Here is pull request for this feature: github.com/flutter/flutter/pull/27058

                  – Michał Powłoka
                  Feb 19 at 18:30

















                When the route is /myRoute/${myID} the path split has 3 items in the list with first being empty string "". Perhaps we have to ignore the path[0] and make use of path[1] and path[2]?

                – Gogu
                Nov 29 '17 at 18:59





                When the route is /myRoute/${myID} the path split has 3 items in the list with first being empty string "". Perhaps we have to ignore the path[0] and make use of path[1] and path[2]?

                – Gogu
                Nov 29 '17 at 18:59













                I'd remove the first '/' in the route instead. But this is just an example, you're free to use whatever you want to.

                – Rémi Rousselet
                Nov 29 '17 at 19:02





                I'd remove the first '/' in the route instead. But this is just an example, you're free to use whatever you want to.

                – Rémi Rousselet
                Nov 29 '17 at 19:02




                2




                2





                Is the above answer still valid? I cannot see arguments property available via RouteSettings...

                – Angel Todorov
                Feb 5 at 16:35





                Is the above answer still valid? I cannot see arguments property available via RouteSettings...

                – Angel Todorov
                Feb 5 at 16:35




                1




                1





                It has been added very recently. You may want to switch of channel.

                – Rémi Rousselet
                Feb 5 at 17:57





                It has been added very recently. You may want to switch of channel.

                – Rémi Rousselet
                Feb 5 at 17:57




                1




                1





                Here is pull request for this feature: github.com/flutter/flutter/pull/27058

                – Michał Powłoka
                Feb 19 at 18:30





                Here is pull request for this feature: github.com/flutter/flutter/pull/27058

                – Michał Powłoka
                Feb 19 at 18:30













                1














                For the outcome of this problem, I developed the package



                link: https://pub.dartlang.org/packages/navigate



                That provide to much your expect and easy to use



                Navigate.navigate(context,
                "home",
                transactionType:TransactionType.fromLeft , // optional
                replaceRoute: ReplaceRoute.thisOne, //optional
                arg: {"transactionType":TransactionType.fromLeft,"replaceRoute":ReplaceRoute.thisOne} //optional
                );





                share|improve this answer





















                • 1





                  You should mention you are the author of that package.

                  – Duncan Jones
                  Dec 26 '18 at 9:20
















                1














                For the outcome of this problem, I developed the package



                link: https://pub.dartlang.org/packages/navigate



                That provide to much your expect and easy to use



                Navigate.navigate(context,
                "home",
                transactionType:TransactionType.fromLeft , // optional
                replaceRoute: ReplaceRoute.thisOne, //optional
                arg: {"transactionType":TransactionType.fromLeft,"replaceRoute":ReplaceRoute.thisOne} //optional
                );





                share|improve this answer





















                • 1





                  You should mention you are the author of that package.

                  – Duncan Jones
                  Dec 26 '18 at 9:20














                1












                1








                1







                For the outcome of this problem, I developed the package



                link: https://pub.dartlang.org/packages/navigate



                That provide to much your expect and easy to use



                Navigate.navigate(context,
                "home",
                transactionType:TransactionType.fromLeft , // optional
                replaceRoute: ReplaceRoute.thisOne, //optional
                arg: {"transactionType":TransactionType.fromLeft,"replaceRoute":ReplaceRoute.thisOne} //optional
                );





                share|improve this answer















                For the outcome of this problem, I developed the package



                link: https://pub.dartlang.org/packages/navigate



                That provide to much your expect and easy to use



                Navigate.navigate(context,
                "home",
                transactionType:TransactionType.fromLeft , // optional
                replaceRoute: ReplaceRoute.thisOne, //optional
                arg: {"transactionType":TransactionType.fromLeft,"replaceRoute":ReplaceRoute.thisOne} //optional
                );






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Dec 26 '18 at 10:37

























                answered Aug 23 '18 at 6:54









                Ravindra BhanderiRavindra Bhanderi

                558318




                558318








                • 1





                  You should mention you are the author of that package.

                  – Duncan Jones
                  Dec 26 '18 at 9:20














                • 1





                  You should mention you are the author of that package.

                  – Duncan Jones
                  Dec 26 '18 at 9:20








                1




                1





                You should mention you are the author of that package.

                – Duncan Jones
                Dec 26 '18 at 9:20





                You should mention you are the author of that package.

                – Duncan Jones
                Dec 26 '18 at 9:20











                0














                I am capturing images with camera then passing them through to a confirmation page like so:



                   ImagePicker.pickImage(source: source).then((File file) {
                Navigator.push(
                context,
                MaterialPageRoute(
                builder: (context) => MediaCaptured(file: file),
                ));
                });


                You could easily do the same with any type of file or non-string data.



                var foo = "non-string data";
                Navigator.push(
                context,
                MaterialPageRoute(
                builder: (context) => MediaCaptured(foo: foo),
                ));


                Call the next page in the route by it's class name, as above.



                Just make sure your new page accepts this in it's constructor.



                 // Stateful Widget
                class MediaCaptured extends StatefulWidget {
                MediaCaptured({ Key key, @required this.foo,}) : super(key: key);
                final var foo;
                }

                // StatelessWidget
                class MediaCaptured extends StatelessWidget {
                MediaCaptured(this.foo);
                var foo;
                }





                share|improve this answer




























                  0














                  I am capturing images with camera then passing them through to a confirmation page like so:



                     ImagePicker.pickImage(source: source).then((File file) {
                  Navigator.push(
                  context,
                  MaterialPageRoute(
                  builder: (context) => MediaCaptured(file: file),
                  ));
                  });


                  You could easily do the same with any type of file or non-string data.



                  var foo = "non-string data";
                  Navigator.push(
                  context,
                  MaterialPageRoute(
                  builder: (context) => MediaCaptured(foo: foo),
                  ));


                  Call the next page in the route by it's class name, as above.



                  Just make sure your new page accepts this in it's constructor.



                   // Stateful Widget
                  class MediaCaptured extends StatefulWidget {
                  MediaCaptured({ Key key, @required this.foo,}) : super(key: key);
                  final var foo;
                  }

                  // StatelessWidget
                  class MediaCaptured extends StatelessWidget {
                  MediaCaptured(this.foo);
                  var foo;
                  }





                  share|improve this answer


























                    0












                    0








                    0







                    I am capturing images with camera then passing them through to a confirmation page like so:



                       ImagePicker.pickImage(source: source).then((File file) {
                    Navigator.push(
                    context,
                    MaterialPageRoute(
                    builder: (context) => MediaCaptured(file: file),
                    ));
                    });


                    You could easily do the same with any type of file or non-string data.



                    var foo = "non-string data";
                    Navigator.push(
                    context,
                    MaterialPageRoute(
                    builder: (context) => MediaCaptured(foo: foo),
                    ));


                    Call the next page in the route by it's class name, as above.



                    Just make sure your new page accepts this in it's constructor.



                     // Stateful Widget
                    class MediaCaptured extends StatefulWidget {
                    MediaCaptured({ Key key, @required this.foo,}) : super(key: key);
                    final var foo;
                    }

                    // StatelessWidget
                    class MediaCaptured extends StatelessWidget {
                    MediaCaptured(this.foo);
                    var foo;
                    }





                    share|improve this answer













                    I am capturing images with camera then passing them through to a confirmation page like so:



                       ImagePicker.pickImage(source: source).then((File file) {
                    Navigator.push(
                    context,
                    MaterialPageRoute(
                    builder: (context) => MediaCaptured(file: file),
                    ));
                    });


                    You could easily do the same with any type of file or non-string data.



                    var foo = "non-string data";
                    Navigator.push(
                    context,
                    MaterialPageRoute(
                    builder: (context) => MediaCaptured(foo: foo),
                    ));


                    Call the next page in the route by it's class name, as above.



                    Just make sure your new page accepts this in it's constructor.



                     // Stateful Widget
                    class MediaCaptured extends StatefulWidget {
                    MediaCaptured({ Key key, @required this.foo,}) : super(key: key);
                    final var foo;
                    }

                    // StatelessWidget
                    class MediaCaptured extends StatelessWidget {
                    MediaCaptured(this.foo);
                    var foo;
                    }






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Aug 16 '18 at 16:28









                    SeanThomasSeanThomas

                    12




                    12























                        0














                        The Flutter Cookbook shows how to navigate to a new page and pass non-string data to it.



                        Passing data to next page



                        I started with Navigator.pushedNamed() because it was simple and I didn't have any data to pass. When my needs changed and I wanted to pass data, I switched to Navigator.push().



                        Example:



                        var nextPageData = {foo:'bar'};

                        Navigator.push(
                        context,
                        MaterialPageRoute(builder: (context) =>
                        MyNextPage(myData: nextPageData))
                        );





                        share|improve this answer




























                          0














                          The Flutter Cookbook shows how to navigate to a new page and pass non-string data to it.



                          Passing data to next page



                          I started with Navigator.pushedNamed() because it was simple and I didn't have any data to pass. When my needs changed and I wanted to pass data, I switched to Navigator.push().



                          Example:



                          var nextPageData = {foo:'bar'};

                          Navigator.push(
                          context,
                          MaterialPageRoute(builder: (context) =>
                          MyNextPage(myData: nextPageData))
                          );





                          share|improve this answer


























                            0












                            0








                            0







                            The Flutter Cookbook shows how to navigate to a new page and pass non-string data to it.



                            Passing data to next page



                            I started with Navigator.pushedNamed() because it was simple and I didn't have any data to pass. When my needs changed and I wanted to pass data, I switched to Navigator.push().



                            Example:



                            var nextPageData = {foo:'bar'};

                            Navigator.push(
                            context,
                            MaterialPageRoute(builder: (context) =>
                            MyNextPage(myData: nextPageData))
                            );





                            share|improve this answer













                            The Flutter Cookbook shows how to navigate to a new page and pass non-string data to it.



                            Passing data to next page



                            I started with Navigator.pushedNamed() because it was simple and I didn't have any data to pass. When my needs changed and I wanted to pass data, I switched to Navigator.push().



                            Example:



                            var nextPageData = {foo:'bar'};

                            Navigator.push(
                            context,
                            MaterialPageRoute(builder: (context) =>
                            MyNextPage(myData: nextPageData))
                            );






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jan 2 at 1:41









                            devdankedevdanke

                            854918




                            854918























                                -4














                                We can pass any type of arguments when declaring routes as constructor arguments as below,

                                For example to send a list of Strings,

                                List<String> titles = ;

                                void main() => runApp(
                                new MaterialApp(
                                home: new FirstPage(),
                                routes: <String, WidgetBuilder>{
                                "/SecondPage": (BuildContext context) => new SecondPage(titles),
                                },
                                ),
                                );

                                class FirstPage extends StatelessWidget {
                                @override
                                Widget build(BuildContext context) {
                                return new Container(
                                child: new RaisedButton(onPressed: () {
                                Navigator.of(context).pushNamed('/SecondPage');
                                }),
                                );
                                }
                                }

                                class SecondPage extends StatelessWidget {
                                final List<String> titles;

                                SecondPage(this.titles);

                                @override
                                Widget build(BuildContext context) {
                                return new ListView.builder(
                                itemBuilder: (context, index) {
                                return new ListTile(
                                title: new Text(titles[index]),
                                );
                                },
                                );
                                }
                                }





                                share|improve this answer




























                                  -4














                                  We can pass any type of arguments when declaring routes as constructor arguments as below,

                                  For example to send a list of Strings,

                                  List<String> titles = ;

                                  void main() => runApp(
                                  new MaterialApp(
                                  home: new FirstPage(),
                                  routes: <String, WidgetBuilder>{
                                  "/SecondPage": (BuildContext context) => new SecondPage(titles),
                                  },
                                  ),
                                  );

                                  class FirstPage extends StatelessWidget {
                                  @override
                                  Widget build(BuildContext context) {
                                  return new Container(
                                  child: new RaisedButton(onPressed: () {
                                  Navigator.of(context).pushNamed('/SecondPage');
                                  }),
                                  );
                                  }
                                  }

                                  class SecondPage extends StatelessWidget {
                                  final List<String> titles;

                                  SecondPage(this.titles);

                                  @override
                                  Widget build(BuildContext context) {
                                  return new ListView.builder(
                                  itemBuilder: (context, index) {
                                  return new ListTile(
                                  title: new Text(titles[index]),
                                  );
                                  },
                                  );
                                  }
                                  }





                                  share|improve this answer


























                                    -4












                                    -4








                                    -4







                                    We can pass any type of arguments when declaring routes as constructor arguments as below,

                                    For example to send a list of Strings,

                                    List<String> titles = ;

                                    void main() => runApp(
                                    new MaterialApp(
                                    home: new FirstPage(),
                                    routes: <String, WidgetBuilder>{
                                    "/SecondPage": (BuildContext context) => new SecondPage(titles),
                                    },
                                    ),
                                    );

                                    class FirstPage extends StatelessWidget {
                                    @override
                                    Widget build(BuildContext context) {
                                    return new Container(
                                    child: new RaisedButton(onPressed: () {
                                    Navigator.of(context).pushNamed('/SecondPage');
                                    }),
                                    );
                                    }
                                    }

                                    class SecondPage extends StatelessWidget {
                                    final List<String> titles;

                                    SecondPage(this.titles);

                                    @override
                                    Widget build(BuildContext context) {
                                    return new ListView.builder(
                                    itemBuilder: (context, index) {
                                    return new ListTile(
                                    title: new Text(titles[index]),
                                    );
                                    },
                                    );
                                    }
                                    }





                                    share|improve this answer













                                    We can pass any type of arguments when declaring routes as constructor arguments as below,

                                    For example to send a list of Strings,

                                    List<String> titles = ;

                                    void main() => runApp(
                                    new MaterialApp(
                                    home: new FirstPage(),
                                    routes: <String, WidgetBuilder>{
                                    "/SecondPage": (BuildContext context) => new SecondPage(titles),
                                    },
                                    ),
                                    );

                                    class FirstPage extends StatelessWidget {
                                    @override
                                    Widget build(BuildContext context) {
                                    return new Container(
                                    child: new RaisedButton(onPressed: () {
                                    Navigator.of(context).pushNamed('/SecondPage');
                                    }),
                                    );
                                    }
                                    }

                                    class SecondPage extends StatelessWidget {
                                    final List<String> titles;

                                    SecondPage(this.titles);

                                    @override
                                    Widget build(BuildContext context) {
                                    return new ListView.builder(
                                    itemBuilder: (context, index) {
                                    return new ListTile(
                                    title: new Text(titles[index]),
                                    );
                                    },
                                    );
                                    }
                                    }






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered May 21 '18 at 12:21









                                    Vinoth KumarVinoth Kumar

                                    1,961519




                                    1,961519






























                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Stack Overflow!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47419908%2fhow-do-i-pass-non-string-data-to-a-named-route-in-flutter%23new-answer', 'question_page');
                                        }
                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        MongoDB - Not Authorized To Execute Command

                                        How to fix TextFormField cause rebuild widget in Flutter

                                        in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith