Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass arguments to widgets when Navigating via named routes #2

Closed
maheshmnj opened this issue Jun 15, 2022 · 1 comment
Closed

Pass arguments to widgets when Navigating via named routes #2

maheshmnj opened this issue Jun 15, 2022 · 1 comment
Labels
Feature Request New feature or request

Comments

@maheshmnj
Copy link
Owner

Figure out a way to pass arguments received in onGenerateRoute to respective widget

 onGeneratedRoute: (RouteSettings settings) {
      print(settings.arguments);
      WidgetBuilder? builder = widget.errorBuilder;
      final nestedLength = widget.destinations[i].length;
       for (int j = 0; j < nestedLength; j++) {
           if (widget.destinations[i][j].path == settings.name) {
                builder = (BuildContext _) => widget.destinations[i][j].widget;
           }
       }
         return MaterialPageRoute(
             builder: builder!, settings: settings);
 }),
@maheshmnj maheshmnj added the Feature Request New feature or request label Jun 15, 2022
@maheshmnj maheshmnj changed the title Pass arguments to widgets when Navigating Pass arguments to widgets when Navigating via named routes Jun 15, 2022
@maheshmnj
Copy link
Owner Author

This is currently possible as below

navigate(context, ProductDetail.route,
isRootNavigator: false,
arguments: {'id': index.toString()});
},

final args = ModalRoute.of(context)!.settings.arguments as Map;
final argsId = args['id'];
return Scaffold(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant