Flutter Collection how to groupBy a list inside a list

I have list like this

[
  {
      "date":"2024/01/01",
      "total":20
      "detail":[
         {
            "person":"amir",
            "income":5
         },
         {
            "person":"james",
            "income":10
         },
         {
            "person":"kevin",
            "income":3
         }
      ]
   },
  {
      "date":"2024/01/02",
      "total":30
      "detail":[
         {
            "person":"thomas",
            "income":5
         },
         {
            "person":"james",
            "income":11
         },
         {
            "person":"kevin",
            "income":10
         }
      ]
   },
  {
      "date":"2024/02/01",
      "total":20
      "detail":[
         {
            "person":"amir",
            "income":5
         },
         {
            "person":"james",
            "income":10
         },
         {
            "person":"kevin",
            "income":3
         }
      ]
   },
  {
      "date":"2024/02/03",
      "total":20
      "detail":[
         {
            "person":"amir",
            "income":5
         },
         {
            "person":"james",
            "income":10
         },
         {
            "person":"kevin",
            "income":3
         }
      ]
   },
  {
      "date":"2024/02/04",
      "total":20
      "detail":[
         {
            "person":"rodrigo",
            "income":5
         },
         {
            "person":"james",
            "income":10
         },
         {
            "person":"kevin",
            "income":3
         }
      ]
   },
  {
      "date":"2024/03/03",
      "total":20
      "detail":[
         {
            "person":"amir",
            "income":5
         },
         {
            "person":"james",
            "income":10
         },
         {
            "person":"frans",
            "income":3
         }
      ]
   },

]

Which the original class is

class StaffIncome {
  const StaffIncome({required this.person, required this.income});
  final String person;
  final double income;


}
 class DailySummary {
 const DailySummary({
    required this.date,
    required this.total,
    this.incomeList = const <StaffIncome>[],
  });


  final DateTime date;
  final double total;
  final List<StaffIncome> incomeList;

}

I want to group it so it will based on month, and it sum for (total ), and for the income of each staff will be summed

so that list will be generated like this

[ 
  {
       "month":"01",
       "year":"2024",
       "total":50,
       "detail":[
           {
              "person":"amir",
              "monthlyIncome":5 
           },      
           {
              "person":"james",
              "monthlyIncome":21 
           },      
           {
              "person":"kevin",
              "monthlyIncome":13 
           },      
           {
              "person":"thomas",
              "monthlyIncome":5 
           },      
                ] 
  },
  {
       "month":"02",
       "year":"2024",
       "total":60,
       "detail":[
           {
              "person":"amir",
              "monthlyIncome":10 
           },      
           {
              "person":"james",
              "monthlyIncome":30 
           },      
           {
              "person":"kevin",
              "monthlyIncome":9 
           },      
           {
              "person":"rodrigo",
              "monthlyIncome":5 
           },      
                ] 
  },
  {
       "month":"03",
       "year":"2024",
       "total":20,
       "detail":[
           {
              "person":"amir",
              "monthlyIncome":5 
           },      
           {
              "person":"james",
              "monthlyIncome":10 
           },      
           {
              "person":"frans",
              "monthlyIncome":3 
           },      
                ], 
  },
]

I have successfull with the use of fluter collection to group by month and year for the total

class MonthYearFilterModel extends Equatable {
  const MonthYearFilterModel({required this.year, required this.month});

  final int year;
  final int month;

  @override
  List<Object?> get props => [
        year,
        month,
      ];
}

class MonthlyTotal extends Equatable {
  const MonthlyTotal({
    required this.monthYear,
    required this.total,
  });
  final MonthYearFilterModel monthYear;
  final double total;

  @override
  List<Object?> get props => [
        monthYear,
        total,
      ];
}

and the code is like this

Map<MonthYearFilterModel, double> _groupByMonthAndSumTotal(
  List<DailySummary> list,
  MonthYearFilterModel Function(DailySummary) groupByGetter,
  double Function(List<double>) applyFunction,
) {
  final tmpMap =
      groupBy<DailySummary, MonthYearFilterModel>(list, groupByGetter);

  return tmpMap.map((key, value) {
    return MapEntry(
      key,
      applyFunction(
        value.map((e) {
          return e.total;
        }).toList(),
      ),
    );
  });
}

List<MonthlyTotal> monthlySalesList({
  required List<DailySummary> listDailySummary,
}) {
  double sumDouble(List<double> list) => list.fold(
        0,
        (previousValue, element) => previousValue + element,
      );

  final mapRes = _groupByMonthAndSumTotal(
    listDailySummary,
    (e) {
      return MonthYearFilterModel(
        month: e.date.month,
        year: e.date.year,
      );
    },
    sumDouble,
  );

  final res = <MonthlyTotal>[];
  mapRes.forEach((k, v) {
    res.add(
      MonthlyTotal(
        monthYear: k,
        total: v,
      ),
    );
  });

  return res;
}

Note : ie, there are 6 person (amir, james, kevin, thomas, rodrigo, frans ), it may be more people

Thank you for your answer / contribution / help

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật