Question: I want to sort a `Map<String,int>` by values.

```
{'201': 4, '2017CS197': 2, '2017CS300': 6, '202': 4, '205': 3, '206': 3, '207': 5}

```

this is my map.

after i want to get result as {'2017CS300': 6,'207':5,'202':4,'201':4,'206':3,'205':3,'2017CS197':2}

Thank You!

Answer: 
To **sort a map by its value in ascending order** in Dart :

```
Map<String, int> map = {'one': 10, 'two': 5, 'three': 7, 'four': 0};

var mapEntries = map.entries.toList()
  ..sort((a, b) => a.value.compareTo(b.value));

map
  ..clear()
  ..addEntries(mapEntries);

print(map); // Must print: {four: 0, two: 5, three: 7, one: 10}

```
I suppose that you could use `SortedMap` from [this package](https://pub.dev/packages/sortedmap): 

> 
> Unlike `SplayTreeMap` the objects can be ordered on both key and value or a combination of both.
> 
> 
>