Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return type 'Map<String,Dynamic>' isn't a string, as defined by anonymous closure

Tags:

flutter

dart

I am trying to create a list using List<E>.generate(length, generator) function but it giving an error The return type Map<String, Dynamic> isn't a string, as defined by anonymous closure.

Here is the code.

List<String> _generateList() {
    return List<String>.generate(20, (i) => {"Hello $i"});
}

Error:

enter image description here

like image 837
Nikhil Bansal Avatar asked Dec 22 '25 08:12

Nikhil Bansal


1 Answers

List<String> _generateList() {
    return List<String>.generate(20, (i) => "Hello $i");
}

Removed the curly brackets in the return statement.

like image 59
Lord Null Avatar answered Dec 24 '25 02:12

Lord Null



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!