Flutter 中的常用方法

Map

map分组

// String是key,可以是String或者int类型
//分组
          Map> map = new Map.fromIterable(brandinfos,
              key: (key) => key.firstLetter,
              value: (value) {
                return brandinfos.where((item) => item.firstLetter == value.firstLetter).toList();
          });
 //或
Map> mapBrandinfos = groupBy(brandinfos, (Brandinfos.firstLetter) => brandinfo.firstLetter);

map 排序

final Map> mapBrand = SplayTreeMap.from(map, (a, b) => a.compareTo(b));

map便利

mapBrand.forEach((k,v) {
            print('$k --- ${v.map((value) => value.name).join(",")}');
          });

你可能感兴趣的:(Flutter 中的常用方法)