how to sort list by date – flutter/dart


This Content is from Stack Overflow. Question asked by shakky

I’m using storage access framework to get media files from specific directory. I’m making the use of saf.cache() method which returns the list of string (basically media path)

but I need to sort this list of string by creation time/date. How can I do that?

  Future<List<String>> fetchImages() async {

      Saf saf = Saf('specific_directory');
      List<String>? cacheList = await saf.cache();
      List<String> imageList = cacheList!.where((element) => element.endsWith('.jpg')).toList(); // it returns In random order
      return imageList;


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?