0
var stars = new Map<String,Map<String,String>>();
  Map<String,String> xx = {
    'test' : 'test'
  };
  stars.putIfAbsent('String', xx);

im getting this error the argument type Map<String,String> cant be assigned to the parameter type Map<String,String>Function(), i don't know what's this Function() at the end of the map, i know this maybe a stupid question but i really dont know where to read about it because i found nothing helpful at official dart docs . thanks in advance

4
  • 1
    As @Ovidiu as said, the parameter 'xx' should be a function and not a value. Check the docs here: api.dartlang.org/stable/2.4.1/dart-core/Map/putIfAbsent.html Commented Aug 10, 2019 at 22:51
  • 1
    thanks. i just needed this peace of documentation. actually i thought there is something with map structure not with putIfAbsent. thank you again Commented Aug 11, 2019 at 4:40
  • if you found the comment helpful, don't forget to upvote it. Thanks. Commented Aug 12, 2019 at 8:16
  • i wish you have put your comment in answer i will accept it since i was looking for documentation more than a peace of code Commented Aug 12, 2019 at 9:44

1 Answer 1

2

putIfAbsent requires the 2nd parameter to be a function, not a value. Try this code:

stars.putIfAbsent('String', () => xx);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.