I am new to development. I am having issue with existing code I code from my fellow developer. They guy sorted a list using a model and compare the version but it only returns one element of the list. This is my code
static NavigationalCatalogDto getLatestVersionCatalog(
List<NavigationalCatalogDto> navigationalCatalogList) {
navigationalCatalogList.sort((b, a) => a.version!.compareTo(b.version!));
return navigationalCatalogList[0];
}
I want to return all the items inside the list after sorting. please help me
You can simply remove the [0] so it does not select the first element. Remember to change the return type of the method as well.
static List<NavigationalCatalogDto> getLatestVersionCatalog(
List<NavigationalCatalogDto> navigationalCatalogList) {
return navigationalCatalogList.sort((b, a) => a.version!.compareTo(b.version!));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.