Home > Back-end >  Unable to Pass Arguments to Component in Flutter
Unable to Pass Arguments to Component in Flutter

Time:08-15

I am struggling to pass arguments to a component in flutter.

The sending Widget has the code:

onTap: () => Navigator.of(context).pushNamed(ImageDisplay.routeName, arguments:{'file','test'}),

The receiving widget has:

final Map<String,String> args = ModalRoute.of(context)!.settings.arguments as Map<String,String>;

The error is:

Exception has occurred. _CastError (type '_CompactLinkedHashSet' is not a subtype of type 'Map<String, String>' in type cast)

Fluter version is:

Flutter 2.10.3 • channel stable • https://github.com/flutter/flutter.git Framework • revision 7e9793dee1 (6 months ago) • 2022-03-02 11:23:12 -0600 Engine • revision bd539267b4 Tools • Dart 2.16.1 • DevTools 2.9.2

I am following from https://docs.flutter.dev/cookbook/navigation/navigate-with-arguments

CodePudding user response:

You are passing a Set and not a Map.

This

{'file','test'}

is a Set with two elements.

I believe this is the map you actually wanted:

{'file':'test'}
  • Related