title: Flutter Firebase not able to get value outside loop
body: <p>I have been using realtime database and trying to fetch some data which I get easily from database but problem is I can't able to get those data outside of the loop below is my code</p>
  <p>This is the value avaialbleTimeSlots</p>
  <pre><code>  var availableTimeSlotsFm1 = [
        &quot;2021-05-08 13:00:00.000&quot;,
        &quot;2021-05-08 13:30:00.000&quot;,
        &quot;2021-05-08 14:00:00.000&quot;,
        &quot;2021-05-08 14:30:00.000&quot;,
        &quot;2021-05-08 15:00:00.000&quot;,
        &quot;2021-05-08 15:30:00.000&quot;,
        &quot;2021-05-08 16:00:00.000&quot;,
        &quot;2021-05-08 16:30:00.000&quot;,
        &quot;2021-05-08 17:00:00.000&quot;,
        &quot;2021-05-08 17:30:00.000&quot;
    ];
  </code></pre>
  <p>Now this is how I fetch value from database and remove time from</p>
  <pre><code>  List providerListd = [
       &quot;2Bauty9IKISrtETSnUaK9uzaon42&quot;,
       &quot;P9qtqNACxfT6isDtO5B1ONHpeiy2&quot;
    ];
    final bookedTming = [];
    var output;
  
    void getBookingTimeSlot() {
        List&lt;dynamic&gt; _bookeFilterdTime = [];
  
        for (var provider in providerListd) {
           if (provider != null) {
             DatabaseReference providerTripRef = FirebaseDatabase.instance
             .reference()
             .child('availableProviderList/${provider}/bookingTime');
             providerTripRef.once().then((DataSnapshot snapshot) {
                 Map&lt;dynamic, dynamic&gt; values = snapshot.value;
                 var results = [];
                 values.forEach((key, values) {
                     var bookingSlot =
                       new DateTime.fromMillisecondsSinceEpoch(values['time']);
                     bookedTming.add(bookingSlot.toString());
          
                 });
  
                 output = bookedTming
                   .groupListsBy((e) =&gt; e)
                   .values
                   .where((e) =&gt; e.length &gt; 1)
                   .map((e) =&gt; e.first)
                   .toList();
  
               // This is the value of `output` fetched from database
               // [2021-05-08 13:30:00.000, 2021-05-08 15:30:00.000, 2021-05-08 17:00:00.000]
               // and those needs to be removed from availableTimeSlotsFm1 so if I print 
               // inside it works fine but not outside 
  
             
                  availableTimeSlotsFm1
                     .removeWhere((e) =&gt; output.contains(e.toString()));
        
                return output;
       
              });
          }
      } 
   }
  </code></pre>
  <p>Expected behaviour is if I print <code>availableTimeSlotsFm1</code> then the value should be like this</p>
  <pre><code>var availableTimeSlotsFm1 = [
     
     &quot;2021-05-08 13:30:00.000&quot;,
     &quot;2021-05-08 14:00:00.000&quot;,
     &quot;2021-05-08 14:30:00.000&quot;,
     
     &quot;2021-05-08 15:30:00.000&quot;,
     &quot;2021-05-08 16:00:00.000&quot;,
     &quot;2021-05-08 16:30:00.000&quot;,
    
     &quot;2021-05-08 17:30:00.000&quot;
  ];
  </code></pre>
  <p>I tried everything but I always get null value of <code>output</code> and same value for <code>availableTimeSlotsFm1</code></p>