Here are a couple of simple Dart maps, created using map literals:

    Note: Dart infers that has the type Map<String, String> and nobleGases has the type Map<int, String>. If you try to add the wrong type of value to either map, the analyzer or runtime raises an error. For more information, read about

    You can create the same objects using a Map constructor:

    1. var gifts = Map();
    2. gifts['first'] = 'partridge';
    3. gifts['second'] = 'turtledoves';
    4. gifts['fifth'] = 'golden rings';
    5. var nobleGases = Map();
    6. nobleGases[2] = 'helium';
    7. nobleGases[10] = 'neon';
    8. nobleGases[18] = 'argon';

    Add a new key-value pair to an existing map just as you would inJavaScript:

    Retrieve a value from a map the same way you would in JavaScript:

    1. assert(gifts['first'] == 'partridge');

    If you look for a key that isn’t in a map, you get a null in return:

    1. var gifts = {'first': 'partridge'};
    2. gifts['fourth'] = 'calling birds';
    3. assert(gifts.length == 2);

    To create a map that’s a compile-time constant,add const before the map literal:

    As of Dart 2.3, maps support spread operators ( and )and collection if and for, just like lists do.For details and examples, see thespread operator proposal and the

    For more information about maps, seeGenerics and.