Yes, it is possible to transform an argument of type QuerySnapshot<Object?>
into an argument of type AsyncSnapshot<QuerySnapshot<Map<String, dynamic>>>
.
You can create a StreamBuilder
or FutureBuilder
widget that takes an argument of type QuerySnapshot<Object?>
and returns an AsyncSnapshot<QuerySnapshot<Map<String, dynamic>>>
by mapping the QuerySnapshot<Object?>
to QuerySnapshot<Map<String, dynamic>>
.
Here's an example of how to do it:
StreamBuilder<QuerySnapshot<Object?>>(
stream: Firestore.instance.collection('users').snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Center(child: CircularProgressIndicator());
}
return SomeWidget(
snapshot: AsyncSnapshot<QuerySnapshot<Map<String, dynamic>>>(
ConnectionState.active,
snapshot: snapshot.data!.map((doc) =>
QueryDocumentSnapshot<Map<String, dynamic>>.fromMap(doc.data() as Map<String, dynamic>))
as QuerySnapshot<Map<String, dynamic>>
),
),
);
},
);
In the above example, the StreamBuilder
takes an argument of type QuerySnapshot<Object?>
and returns an AsyncSnapshot<QuerySnapshot<Map<String, dynamic>>>
by mapping each document in the snapshot to a QueryDocumentSnapshot<Map<String, dynamic>>
.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-07-21 09:21:12 +0000
Seen: 11 times
Last updated: Jul 21 '23
What is the method to transmit a map<String,Map<String,Integer>> along with application.properties?
What is the procedure to remove all markers and layers from a Leaflet map in order to add new ones?
How can I get the choropleth map to display on Jupyter Notebook when using Plotly Express?
How can I show several locations on a Leaflet map using GraphHopper?
How do I obtain Latin-1 codes for particular characters?
How can one go over a key/value map object by repeatedly executing its elements?
How can one display grid labels on a Southpolar stereographic map in cartopy?