ThinkDigital
ThinkDigital

Reputation: 3539

Error: "type 'String' is not a subtype of type 'int'" when mapping a Dart Map

I have a map structured like so:

Map<dynamic, dynamic> optionsMap = {1: true, 2: false, ..., "totalCount": 1};

I explicitly declared the values as dynamic to avoid Dart's intelligent typing, even though it should handle this and make it dynamic.

I'm going to map it to provide a Map with the ending structure:

{1:{index1Name:index1Value}, 2:{index2Name:index2Value}...}

When trying to map this Map, using

Map optionsMap = optionsState.map(
        (dynamic key, dynamic value) => MapEntry(key, [options[key], value]));

I get the following error:

type 'String' is not a subtype of type 'int'

I never strong typed an int. Why do I get this error?

Upvotes: 0

Views: 574

Answers (1)

Jerry Jian
Jerry Jian

Reputation: 26

What's the type of the options variable? If it is a list, the error may be caused by MapEntry(key, [options[key], value]) within the map function running at

options['totalCount']

Upvotes: 1

Related Questions