How to Converting a List of DateTime into Strings ?

This Article is posted by nikhilchaudhary12155 at 10/29/2019 4:05:34 AM




Hello Everyone,
Today we are talking about how to convert a list of date and time into string.
First of all, you know about list.map concept before learning of these things.

The code block inside list.map is never executed.

This is because list.map produces a lazy transformation of the list. The transformation function is executed only when elements are requested from it.

You probably want to use:

var dates = list.map((DateTime time) {
      var dateRange = DateFormat("MM-dd-yy").format(time);
      return dateRange;
});
print(dates);

In the code above, it is the print function that forces the transformation to run.

Alternatively, you can transform the result of the list.map to a list using

var datesList = dates.toList();

Again, this forces eager evaluation of the map transformation.




Tags: flutter flutterisfuture








0 Comments
Login to comment.
Recent Comments

Be the first to Comment. You can ask a Query or Share your toughts or Just say thanks.


© 2018 - Fluttercentral | Email to me - seven.srikanth@gmail.com