Two ways to create unmodifiable dart map

You can’t add or change any unmodifiable dart map. Following are the two different ways to create one unmodifiable map :

  1. Using const keyword
  2. Using Map.unmodifiable
main(List<String> args) {
  var map1 = const {"name": "Alex", "age": 29};

  var map2 = Map.unmodifiable({"name": "Bob", "age": 30});
  // map1["hello"]= 33;
  // map2["hello"] = 44;
}

Uncomment the last two lines. It will throw one exception :

Unhandled exception:
Unsupported operation: Cannot modify unmodifiable map