Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to Pass Arguments to Component in Flutter

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’}),

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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'}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading