title: Passing Firebase current user (as Future) as a parameter to a query in a Stream. Is it possible or is there another way?
body: <p>I have a Stream building a list from a Firebase collection QuerySnapShot. The query and the stream builder work great, if I don't pass variable data to the query (the 'where' statement). However, what I am trying to do is pass the FirebaseAuth.currentUser as a filter in the where clause of my Stream. </p>
  
  <p>I am sure there is something I am not understanding about making these 2 separate async calls. </p>
  
  <p>Basically I need to get the uid of the currently authenticated user and pass that into the query in my stream.</p>
  
  <p>I am super new to Flutter and am on a rapid fast track to get my chops. Been fully immersed for about a week.</p>
  
  <pre><code>class Booking {
  
    final DateTime startTime;
    final DateTime endTime;
    final String name;
    final String bookingId;
    final String truckID;
  
    Booking({ this.bookingId, this.truckID, this.startTime, this.endTime, this.name });
  }
  </code></pre>
  
  <pre><code>// build the booking list from the QuerySnapShot
    List&lt;Booking&gt; _bookingListFromSnapshot(QuerySnapshot snapshot) {
      return snapshot.documents.map((doc) {
        return Booking(
            bookingId: doc.documentID ?? '',
            name: doc.data['name'] ?? '',
            startTime: doc.data['startTime'].toDate() ?? '',
            endTime: doc.data['endTime'].toDate() ?? '',
            truckID: doc.data['truckID']
        );
      }).toList();
    }
  </code></pre>
  
  <pre><code>//asynchronously get the uid of the currentuser from FirebaseAuth
    Future&lt;String&gt; inputData() async {
      final FirebaseUser _aUser = await FirebaseAuth.instance.currentUser();
      final String _uid = _aUser.uid.toString();
      return _uid;
    }
  </code></pre>
  
  <p>Here is where I am trying to pass the current user into the Stream</p>
  
  <pre><code>  //get user specific booking stream
    Stream&lt;List&lt;Booking&gt;&gt; get bookings {
      final _myUserId = inputData();  
      return bookingCollection
          .where("truckID", isEqualTo: _myUserId) //Instance of 'Future&lt;String&gt;'...needs to be the uid of the current user.
          .snapshots()
          .map(_bookingListFromSnapshot);
        }
  </code></pre>
  
  <pre><code>// the widget consuming the list
  class _BookingListState extends State&lt;BookingList&gt; {
    @override
    Widget build(BuildContext context) {
      final bookings = Provider.of&lt;List&lt;Booking&gt;&gt;(context) ?? [];
  
      return ListView.builder(
        itemCount: bookings.length,
        itemBuilder: (context,index){
          return BookingTile(booking: bookings[index]);
        },
      );
    }
  }
  </code></pre>
  
  <p><strong>EDIT to include the Stream usage for feedback (after wrapping the Stream in a Future as suggested)</strong></p>
  
  <p>In my home.dart file I listen for the <code>Stream&lt;List&lt;Booking&gt;&gt;&gt;</code> so I can build the list of bookings that are displayed on that page. In this next block I now get an error that I cannot assign the parameter type <code>Stream&lt;List&lt;Booking&gt;&gt;</code> to the argument type <code>Future&lt;Stream&lt;List&lt;Booking&gt;&gt;&gt;</code>. The compiler suggests changing the parameter type or casting the argument to <code>&lt;Stream&lt;list&lt;Booking&gt;&gt;</code></p>
  
  <p>The full compile message </p>
  
  <pre><code>lib/screens/home/home.dart:38:32: Error: The argument type 'Future&lt;Stream&lt;List&lt;Booking&gt;&gt;&gt;' can't be assigned to the parameter type 'Stream&lt;List&lt;Booking&gt;&gt;'.
   - 'Future' is from 'dart:async'.
   - 'Stream' is from 'dart:async'.
   - 'List' is from 'dart:core'.
   - 'Booking' is from 'package:models/booking.dart' ('lib/models/booking.dart').
  Try changing the type of the parameter, or casting the argument to 'Stream&lt;List&lt;Booking&gt;&gt;'.
        value: DatabaseService().bookings,
  </code></pre>
  
  <p><strong>home.dart</strong></p>
  
  <pre><code>return StreamProvider&lt;List&lt;Booking&gt;&gt;.value(
        value: DatabaseService().bookings, 
        child: Scaffold( ... ) //Scaffold
        ); //StreamProvider.value
  </code></pre>
  
  <p>I have tried changing either the parameter <code>value</code> or the argument <code>DatabaseService().value</code> to the suggested types...and I have failed :)</p>
  
  <p><strong>modified bookings getter after I changed it based on feedback</strong></p>
  
  <pre><code>  //get user specific booking stream
    Future&lt;Stream&lt;List&lt;Booking&gt;&gt;&gt; get bookings async {
      final _myUserId = await inputData();
      print(_myUserId);
      return bookingCollection
          .where("truckID", isEqualTo: _myUserId) //here is where I want to pass the currentUser
          .snapshots()
          .map(_bookingListFromSnapshot);
        }
  </code></pre>