skip to Main Content

I am trying to use a Map(String,String) to satisfy the FormBuilderChipOption. The code I have tried is as follows:

   options:
        languageOptionsMap((city,letter) => FormBuilderChipOption(
          value: Text(city),
          avatar: CircleAvatar(child: Text(letter)),
        )).toList(growable: false),
    
    The Map is as follows:
    
      Map<String,String> languageOptionsMap = {
        'English': 'E',
        'Mandarin': 'M',
        'Hindi': 'H',
        'Spanish': 'S',
        'Arabic': 'A',
        'French': 'F',
        'Swedish': 'S',
        'Danish': 'D',
      };

I get a compile time error as follows:

======== Exception caught by widgets library =======================================================
The following NoSuchMethodError was thrown building CompleteForm(dirty, state: _CompleteFormState#5d199):
'call'
Dynamic call of object has no instance method 'call'.
Receiver: Instance of 'IdentityMap<String, String>'
Arguments: [Instance of '(dynamic, dynamic) => FormBuilderChipOption<Text>']

The relevant error-causing widget was: 
  CompleteForm CompleteForm:file:///C:/Users/stefa/StudioProjects/appformbuilder/lib/main.dart:45:19

I am expecting to get the Value and Avatar for the FormBuilderChipOption.

2

Answers


  1. Chosen as BEST ANSWER

    Thank You setday, as you stated your answer solved my issues.


  2. In dart, you can’t call the Map (it’s not a function or a functional object), so you have to, firstly, get the elements ( .entries ) and, secondly, map them ( .map with function that takes just entry, not (city,letter)):

    options: languageOptionsMap.entries.map((entry) => FormBuilderChipOption( value: entry.key, avatar: CircleAvatar(child: Text(entry.value)), )).toList(growable: false),
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search