Flutter GoRouter how to pass multiple parameters

490 views Asked by At

everyone. I'm new to GoRouter, and I'm looking for guidance for webApp on how to pass multiple parameters in GoRouter. I've seen many examples, but they all use strings, whereas I have parameters of type 'Function' and 'bool'.

Here's my class:

 class EditCustomerPage extends StatefulWidget {
  final Function updateTab;
  final bool edit;

  const EditCustomerPage({
    Key? key,
    required this.updateTab,
    required this.edit,
  }) : super(key: key);

  @override
  _EditCustomerPageState createState() => _EditCustomerPageState();
}
1

There are 1 answers

2
smita On BEST ANSWER

Define route as follows:

GoRoute(
      name: RouteName.EditCustomerPageRoute,
      path: '/EditCustomerPageRoute',
      builder: (context, state) { 
        final data = state.extra! as Map<String,dynamic>;
        return EditCustomerPage(updateTab: data["updateTab"],edit: data["edit"]);
      }
    ),

Call it as follows to navigate:

context.push(RouteName.EditCustomerPageRoute,extra: {"updateTab":updateTabValue,"edit":editValue);