如何为列表中具有共同点的项目创建子列表

How to make sublist to the item in the list which has common

我需要将常见的年龄名称作为子列表排序到相同的年龄列表项下面是包含年龄和名称的列表,这里我想将子列表名称设置为相同的年龄项,需要帮助

        class Details {
  final String name;
  final int age;

  Details(this.name, this.age);

  List <Details> list = [
    { Jack, 21},
    { Adam, 22},
    { Katherin, 24},
    { john, 22},
    { mike, 21}
  ]
}


Expected :
    
       List <Details> list = [
    { 21: ["jack", "mike",]},
    { 22: ["Adam", "john"]},
    { 24: ["Katherin"]}, ]

Here 你可以找到从列表项

中创建公共元素子列表的方法
detailsTypeList = groupBy(list, (Details details) => details.age).entries.toList();