Search code examples
flutterdartroutesargumentsnavigator

How to push multiple Arguments in Named Routes flutter


I'm aware that my question had been asking several time but unfortunately I could not found what I'm looking for there.

I wanna send multiple arguments from one screen to another using On generates routes.

this is my Navigator line, I wanna send along side the selectedAmount the selectedIndexes they both a numbers

Navigator.of(context).pushNamed(AppRoutes.digitalBusinessGuideInstructions, arguments: selectedAmount)

Here is my Routes cases

case AppRoutes.digitalBusinessGuideInstructions:
  final int selectedAmount = settings.arguments as int;
  return AppPageRoute(
    builder: (context) => DigitalBusinessGuideInstructions(
      selectedAmount: selectedAmount,
    ),
  );

Solution

  • You can pass arguments any object, For now I am passing map

    Navigator.of(context).pushNamed(
      "",
      arguments: {
        "item1Key": selectedAmount,
        "item2Key": 3,
      },
    );
    

    And receive like settings.arguments as Map?; then read the map for items

      final args = settings.arguments as Map?;
    
      final selectedAmount = args?["item1Key"];
      final item2Value = args?["item2Key"];