diff --git a/packages/smooth_app/lib/helpers/product_cards_helper.dart b/packages/smooth_app/lib/helpers/product_cards_helper.dart index 64bf8acd5f3..c71f5a576c9 100644 --- a/packages/smooth_app/lib/helpers/product_cards_helper.dart +++ b/packages/smooth_app/lib/helpers/product_cards_helper.dart @@ -410,10 +410,9 @@ List getRawProductImages( final Product product, final ImageSize imageSize, ) { - final List result = []; final List? rawImages = product.getRawImages(); if (rawImages == null) { - return result; + return []; } final Map map = {}; for (final ProductImage productImage in rawImages) { @@ -439,10 +438,22 @@ List getRawProductImages( } map[imageId] = productImage; } - final List sortedIds = List.of(map.keys); - sortedIds.sort(); - for (final int id in sortedIds) { - result.add(map[id]!); - } + final List result = List.of(map.values); + result.sort( + ( + final ProductImage a, + final ProductImage b, + ) { + final int result = (a.uploaded?.millisecondsSinceEpoch ?? 0).compareTo( + b.uploaded?.millisecondsSinceEpoch ?? 0, + ); + if (result != 0) { + return result; + } + return (int.tryParse(a.imgid ?? '0') ?? 0).compareTo( + int.tryParse(b.imgid ?? '0') ?? 0, + ); + }, + ); return result; }