0

Every way I try this it says either the result is null. So I have the function(which is medium) that explicitly returns a Map<String,int> and I'm using this lambda function to feed keys,values into it & this works with no "might return null" warnings

> players.forEach((k, v) => medium(k, v));

I've tried all the naïve ways like just assigning a variable to it, or wrapping it in a callable.

Map<String, dynamic> souvenir(Map lamp) { return lamp.forEach((k, v) => medium(k, v)); }

Whatever way I put it the error is always something along the lines of:

"message": "A value of type 'void' can't be returned from the function 'souvenir' because it has a return type of 'Map<String, dynamic>'.",

Which makes sense because print statements in medium will work fine, but I don't know how to access the Map I'm returning. If I could get a better way to iterate the keys/values or write it to Json that would work too. But I couldn't figure out how I could wrap it in a .toJson function without declaring an object when I was looking at'package:json_annotation/json_annotation.dart'.

1 Answers1

0

forEach is a void method and it can't return anything. Try map() method. Maybe it helps in your case.

Map<String, dynamic> souvenir(Map lamp) { return lamp.map((k, v) => medium(k, v)); }