title: How to return values from a loop using Future.delayed?
body: <p>I want my function to take two dates and return a Double value for the progress bar of the remaining days to the final date.</p>
  <p>My function gives only the first value (56.25% from the example)</p>
  <p>Example:
  Start: 15.07.2022
  End: 31.07.2022
  Now: 23.07.2022
  Days left: 8 (16)
  Progress: 56.25%
  And on July 24, 2022 the function will return 62.5% and etc.</p>
  <p>My experimental code: (Used seconds for clarity)</p>
  <pre><code>    // ignore_for_file: avoid_print
  
  import 'dart:async';
  
  void main() {
    progressDates(DateTime(2022, 7, 15), DateTime(2022, 7, 31));
  }
  
  double progressDates(
    DateTime date1,
    DateTime date2,
  ) {
    DateTime now = DateTime.now();
    DateTime nowDay = DateTime(now.year, now.month, now.day);
    int dif1 = nowDay
        .difference(date1)
        .inDays; // The difference between the beginning and the current day
    int dif2 = date2
        .difference(nowDay)
        .inDays; // The difference between the curent and the end
    int allDays = date2.difference(date1).inDays;
    double inDouble = (dif1 / allDays) * 100;
    double temp = 100 / allDays;
    DateTime current = DateTime.now();
  
    Stream timer = Stream.periodic(const Duration(seconds: 1), (i) {
      current = current.add(const Duration(seconds: 1));
      inDouble = inDouble + temp;
      return inDouble;
    }).take(dif2);
  
    timer.listen((percentage) =&gt; percentage);
    double result = timer as double;
    print(result);
    return result;
  }
  </code></pre>