Answers for "flutter reorder map by key"

0

flutter reorder map by key

//https://stackoverflow.com/questions/30620546/how-to-sort-map-value

import 'dart:collection';

void main() {
  var temp= { 
    'A' : 3,
    'B' : 1,
    'C' : 2
  };

  var sortedKeys = temp.keys.toList(growable:false)
    ..sort((k1, k2) => temp[k1].compareTo(temp[k2]));
    LinkedHashMap sortedMap = new LinkedHashMap
      .fromIterable(sortedKeys, key: (k) => k, value: (k) => temp[k]);
  print(sortedMap);
}
Posted by: Guest on December-19-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language