I make some listview and it have likes and comments section. I want to show how many likes and comments that post had. The like section works by displaying the number of users who like it, i try to show it with snapshot.data.docs.length.toString() from firestore but when i try to show how many comments with same code as like section it not working and only get 0.
this is inside comments field
Padding(
padding: const EdgeInsets.only(top: 8),
child: Padding(
padding: const EdgeInsets.only(left: 15),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: [
Container(
width: 80.0,
child: Row(
mainAxisAlignment:
MainAxisAlignment.start,
children: [
GestureDetector(
onLongPress: () {
Provider.of<PostFunction>(context,
listen: false)
.showLikes(
context,
documentSnapshot
.data()['title']);
},
onTap: () {
print('Adding like...');
Provider.of<PostFunction>(context,
listen: false)
.addLike(
context,
documentSnapshot
.data()['title'],
Provider.of<AuthenticationService>(
context,
listen: false)
.getUserUid);
},
child: Icon(
FontAwesomeIcons.arrowAltCircleUp,
color: kGreyColor,
size: 18.0,
),
),
StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance
.collection('posts')
.doc(documentSnapshot
.data()['title'])
.collection('likes')
.snapshots(),
builder: (context, snapshot) {
if (snapshot.connectionState ==
ConnectionState.waiting) {
return Center(
child:
CircularProgressIndicator());
} else {
return Padding(
padding:
const EdgeInsets.only(
left: 8.0),
child: RichText(
text: TextSpan(
text: snapshot
.data.docs.length
.toString(),
style: GoogleFonts
.openSans(
color:
kGreyColor,
fontSize: 16.0),
children: <TextSpan>[
TextSpan(
text: ' votes',
style: GoogleFonts
.openSans(
color:
kGreyColor,
fontSize: 16.0,
)),
]),
),
);
}
})
],
),
),
SizedBox(width: 20),
Container(
width: 150.0,
child: Row(
mainAxisAlignment:
MainAxisAlignment.start,
children: [
GestureDetector(
onTap: () {
Provider.of<PostFunction>(context,
listen: false)
.showComments(
context,
documentSnapshot,
documentSnapshot
.data()['title']);
},
child: Icon(
FontAwesomeIcons.solidComments,
color: kGreyColor,
size: 16.0,
),
),
StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance
.collection(' posts')
.doc(documentSnapshot
.data()['title'])
.collection('comments')
.snapshots(),
builder: (context, snapshot) {
if (snapshot.connectionState ==
ConnectionState.waiting) {
return Center(
child:
CircularProgressIndicator());
} else {
return Padding(
padding:
const EdgeInsets.only(
left: 8.0),
child: Text(
snapshot.data.docs.length
.toString(),
style: GoogleFonts.openSans(
color: kGreyColor,
fontSize: 16.0),
),
);
}
}),
],
),
),
Spacer(),
Provider.of<AuthenticationService>(context,
listen: false)
.getUserUid ==
documentSnapshot.data()['useruid']
? IconButton(
icon: Icon(EvaIcons.moreVertical,
color: kGreyColor, size: 16),
onPressed: () {
Provider.of<PostFunction>(context,
listen: false)
.showPostOptions(
context,
documentSnapshot
.data()['title']);
})
: Container(width: 0.0, height: 0.0)
],
),
),
),
Replace
.collection(' posts')
with
.collection('posts')
in the “comments” section of the Streambuilder.
Your stream data is coming as empty as the database cannot find a collection with name (“ posts”).
So when you try to show how many comments the post had with the same code as the “likes” section it is not working and only getting 0 each time.
just declare the dataType of builder's arguments..i mean, builder:(BuildContext context,AsyncSnapshot snapShot).check the image
Could you please try this one?
StreamBuilder(
stream: firestoreDB,
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData) {
return Center(child: CircularProgressIndicator());
}
return ListView.builder(
itemCount: snapshot.data!.size,
itemBuilder: (context, index) {
return Card(
child: ListTile(
title: Text(snapshot.data!.docs[index]['name']),
subtitle: Text(snapshot.data!.docs[index]['description']),
),
);
},
);
},
),
Related
I have a collection called pending_appointments and I want to access all of the documents which have the field patienduid equal to the current user's uid. Then there is a stream builder, but snapshots.data becomes null.
Like when I go to that screen, it shows me the expected results for about half a second and then it changes to 'No appointment found'.
Also, if I remove that 'where' statement, it shows me all the pending appointments which is the expect result, but as soon as I add the where statement which should give me the desired result, it goes back to no appointment after showing me the desired results for half a second.
Widget build(BuildContext context) {
return SafeArea(
child: StreamBuilder(
stream: FirebaseFirestore.instance
.collection('pending_appointments')
.where('patientUid', isEqualTo: user.uid)
.orderBy('date')
.snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.connectionState == ConnectionState.active) {
if (snapshot.data != null) {
return ListView.builder(
scrollDirection: Axis.vertical,
physics: ClampingScrollPhysics(),
shrinkWrap: true,
itemCount: snapshot.data.size,
itemBuilder: (context, index) {
DocumentSnapshot document = snapshot.data.docs[index];
print(_compareDate(document['date'].toDate().toString()));
if (_checkDiff(document['date'].toDate())) {
deleteAppointment(document.id);
}
return Card(
elevation: 2,
child: InkWell(
onTap: () {},
child: ExpansionTile(
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.only(left: 5),
child: Text(
'Dr. ${document['doctor']}',
style: GoogleFonts.lato(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
Text(
_compareDate(document['date'].toDate().toString())
? "TODAY"
: "",
style: GoogleFonts.lato(
color: Colors.green,
fontSize: 18,
fontWeight: FontWeight.bold),
),
SizedBox(
width: 0,
),
],
),
subtitle: Padding(
padding: const EdgeInsets.only(left: 5),
child: Text(
_dateFormatter(
document['date'].toDate().toString()),
style: GoogleFonts.lato(),
),
),
children: [
Padding(
padding: const EdgeInsets.only(
bottom: 20, right: 10, left: 16),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Patient name: " + document['name'],
style: GoogleFonts.lato(
fontSize: 16,
),
),
SizedBox(
height: 10,
),
Text(
"Time: " +
_timeFormatter(
document['date']
.toDate()
.toString(),
),
style: GoogleFonts.lato(
fontSize: 16,
),
),
],
),
IconButton(
tooltip: 'Delete Appointment',
icon: Icon(
Icons.delete,
color: Colors.black87,
),
onPressed: () {
print(">>>>>>>>>" + document.id);
_documentID = document.id;
showAlertDialog(context);
},
),
],
),
),
],
),
),
);
},
);
} else {
return Center(
child: Text(
'No Appointment Scheduled',
style: GoogleFonts.lato(
color: Colors.grey,
fontSize: 18,
),
),
);
}
} else {
return Center(
child: CircularProgressIndicator(),
);
}
},
),
);
}
remove this
if (snapshot.connectionState == ConnectionState.active) {
}
add this to your code
if (Snapshot.connectionState == ConnectionState.waiting) {
return Center(child: CircularProgressIndicator());
}
if (Snapshot.connectionState == ConnectionState.none) {
return Container();
}
if (Snapshot.data.docs.isEmpty) {
return Text(
'Document Empty',
style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
);
}
if (!Snapshot.hasData) {
return Text(
'0',
style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
);
}
return ListView.builder(
scrollDirection: Axis.vertical,
physics: ClampingScrollPhysics(),
shrinkWrap: true,
itemCount: snapshot.data.docs.length,
itemBuilder: (context, index) {
final document = snapshot.data.docs[index].data();
print(_compareDate(document['date'].toDate().toString()));
if (_checkDiff(document['date'].toDate())) {
deleteAppointment(document.id);
}
});
I create ToDo App using Flutter. I wnat to receive all todos from collection and sort them by timestamp, but I have todos with same timestamp and I want to receive length of docs inside collection without repeats
As you can see on picture from my app, when I add new task for today or tomorrow blocks with tasks repeated as many times as the tasks with the given time.
How can I receive all docs from Firestore collection if I have same docs, but want to receive length without same docs?
StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance
.collection(uid)
.doc('toDos')
.collection('toDos')
.where('dateTime', isNotEqualTo: DateTime.now())
.orderBy('dateTime', descending: false)
.snapshots(),
builder: (context, snapshots) {
if (snapshots.hasData) {
return ListView.builder(
shrinkWrap: true,
itemCount: snapshots.data.docs.length,
itemBuilder: (context, index) {
DocumentSnapshot documentSnapshots =
snapshots.data.docs[index];
return ListTile(
title: Text(documentSnapshots['dateTime']
.toDate()
.toString()),
subtitle: Container(
color: Colors.redAccent,
child: StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance
.collection(uid)
.doc('toDos')
.collection('toDos')
.orderBy('dateTime',
descending: false)
.snapshots(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return ListView.builder(
physics:
NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount:
snapshot.data.docs.length,
itemBuilder: (context, index) {
DocumentSnapshot
documentSnapshot =
snapshot.data.docs[index];
Timestamp timestamp =
documentSnapshot['dateTime'];
return Dismissible(
background: Container(
decoration: BoxDecoration(
color: Colors.redAccent,
borderRadius:
BorderRadius
.circular(
12.0)),
alignment:
Alignment.centerLeft,
child: Icon(Icons.delete),
),
onDismissed: (direction) =>
DatabaseService()
.deleteToDos(
documentSnapshot[
'todoTitle']),
key: Key(documentSnapshot[
'todoTitle']),
child:
documentSnapshot[
'dateTime'] ==
documentSnapshots[
'dateTime']
? Card(
elevation: 0.7,
shape:
RoundedRectangleBorder(
borderRadius:
BorderRadius
.circular(
12.0,
),
),
child: ListTile(
subtitle: Text(
ChooseLanguageState
.enLang
? '\n' +
dateEng
.format(DateTime.tryParse(timestamp
.toDate()
.toString()))
.toString()
: '\n' +
dateRu
.format(DateTime.tryParse(timestamp.toDate().toString()))
.toString(),
style:
TextStyle(
fontFamily:
'MontserratLight',
fontWeight:
FontWeight
.w200,
color: Colors
.grey,
fontSize:
sizeX.height /
70,
),
),
leading:
Padding(
padding: EdgeInsets
.only(
top:
10,
bottom:
10),
child:
IconButton(
onPressed:
() async {
setState(
() {
DatabaseService()
.completeTask(documentSnapshot['todoTitle']);
});
},
icon: documentSnapshot[
'isComplete']
? SvgPicture
.asset(
'assets/icons/icon_done.svg',
)
: SvgPicture
.asset(
'assets/icons/icon_circle.svg',
color:
Colors.black,
),
),
),
title: Text(
documentSnapshot[
'todoTitle'],
style: TextStyle(
fontFamily:
'MontserratLight',
fontWeight:
FontWeight
.w700,
color: Colors
.black),
),
trailing:
IconButton(
onPressed:
() {
setState(
() {
DatabaseService().deleteToDos(documentSnapshot['todoTitle']);
});
},
icon: SvgPicture
.asset(
'assets/icons/icon_trash.svg',
color:
Colors.redAccent,
)),
),
)
: null);
},
);
} else if (snapshots.hasError) {
const Text('No Data');
}
return Center(
child: CircularProgressIndicator());
}),
),
);
});
} else if (snapshots.hasError) {
const Text('No Data');
}
return Center(
child: Container(),
);
},
),
firestore picture
app picture
I store a selected quarter in a Sqlite database. This quarter is displayed in an appbar along with some text a user can click to take them to a page where they can change the selected quarter. Once the user selects a quarter from the page, I push this neq quarter to the sqlite database so it can be displayed. I also use a Navigator.pop(context); to go back to the previous page when a new quarter is selected. My problem is that once a user selects a new quarter, the quarter isn't displayed on the page they were just on. You have to navigate away to see it or navigate away and back. the FutureBuilder doesn't seem to know that there is new data in the SQLite database that needs to be displayed. How would I go about making it display the new data when a user selects a new quarter? Any help is appreciated! Thanks!
How I display quarters. Also where the button to take you to the page to change quarters is.
#override
Widget build(BuildContext context) {
return Container(
color: Colors.white,
child: FutureBuilder<dynamic>(
future: SessionDBProvider.sessionDB.getSessionObject(),
initialData: List(),
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
return Text('none');
case ConnectionState.waiting:
return Center(child: CircularProgressIndicator());
case ConnectionState.active:
return Text('');
case ConnectionState.done:
if (snapshot.hasError) {
print(
'${snapshot.error}',
);
}
}
List session = snapshot.data;
return Container(
child: Column(children: <Widget>[
Flexible(
flex: 2,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.blue, Colors.red],
begin: Alignment.topRight,
end: Alignment.topLeft,
stops: [0.2, 1])),
child: Container(
margin: EdgeInsets.only(left: 11),
child: Text(
"Test Page",
style: TextStyle(
color: Colors.white,
fontSize: 27,
fontFamily: 'Montserrat',
height: 1.1),
),
),
)
],
),
),
Flexible(
flex: 2,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
margin: EdgeInsets.only(left: 10),
child: Text(
"${session[0].selected_quarter}",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 25),
),
),
],
),
),);
}));
}
This is where you select a new quarter and push it to the Sqlite database.
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[200],
appBar: PreferredSize(
preferredSize: Size.fromHeight(95.0),
child: AppBar(
automaticallyImplyLeading: false, // hides leading widget
flexibleSpace: DataAppBar(),
),
),
body: FutureBuilder<dynamic>(
future: DataDBProvider.dataDB.getData(),
initialData: List(),
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
return Text('none');
case ConnectionState.waiting:
return Center(child: CircularProgressIndicator());
case ConnectionState.active:
return Text('');
case ConnectionState.done:
if (snapshot.hasError) {
print(
'${snapshot.error}',
);
}
}
List data = snapshot.data;
return ListView.builder(
itemCount: snapshot.data.length,
shrinkWrap: true,
itemBuilder: (context, int index) {
return Padding(
padding: EdgeInsets.symmetric(
vertical: 1.0, horizontal: 4.0),
child: Card(
color: (index % 2 == 0) ? greycolor : Colors.white,
child: Container(
height: 60,
padding: EdgeInsets.fromLTRB(0, 20, 0, 0),
child: InkWell(
onTap: () {
Data data = new Data();
data.quarter_status = data[index].status;
data.selected_quarter = data[index].quarter;
DataDBProvider.sessionDB.updateSession(session);
Navigator.pop(context);
},
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
margin: EdgeInsets.only(right: 5),
child: Text(data[index].quarter,
style: TextStyle(
fontSize: 20,
fontFamily: 'Montserrat',
color: Colors.blue),
textAlign: TextAlign.left),
),
],
),
),
),
),
);
},
);
}));
}}
I am facing a problem and I cannot solve it, I have a collection "Posts" that contain users' posts, each post contains a uid of the owner of the post, and I have another collection named "users", and each user has his name and photo, I want to get the user's name and image to display on his post.
Posts Collection
Users Collection
I have seen this article but I did not benefit perhaps because I am a beginner.
My Code:
StreamBuilder(
stream: Firestore.instance
.collection('Posts')
.orderBy('date', descending: true)
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
const Text('Loading...');
} else {
return ListView.builder(
physics:
NeverScrollableScrollPhysics(),
shrinkWrap: true,
scrollDirection: Axis.vertical,
itemCount: snapshot
.data.documents.length,
itemBuilder: (context, index) {
DocumentSnapshot mypost =
snapshot
.data.documents[index];
return Stack(
children: <Widget>[
Container(
decoration:
BoxDecoration(
borderRadius:
BorderRadius
.circular(
15.0),
),
child: Padding(
padding:
EdgeInsets
.all(8.0),
child: Column(
children: <
Widget>[
InkWell(
child: Row(
children: <
Widget>[
Container(
width:
32.0,
height:
32.0,
decoration: BoxDecoration(shape: BoxShape.circle, image: DecorationImage(fit: BoxFit.fill, image: NetworkImage(
// user image url
'Owner of post img')))),
SizedBox(
width:
10.0,
),
Text(
'Owner of post Name',
style: TextStyle(
color: Colors.white,
fontSize: 12.0,
fontWeight: FontWeight.bold,
fontFamily: 'BalooDa2'),
),
],
),
),
Padding(
padding:
EdgeInsets.all(
5.0),
child: Text(
'${mypost['text']}',
style: TextStyle(
color: Colors
.white,
fontSize:
16.0,
fontFamily:
'Tajawal',
height:
1.3),
textAlign:
TextAlign
.justify,
textDirection:
TextDirection.rtl),
),
],
),
),
),
],
);
});
}
return Container(
height: 0.0,
width: 0.0,
);
},
),
You can user nested StreamBuilders to fetch user detail from the uid you are getting from posts collection.I have added a query which will match uid from posts data and look for the documents in users collection where uid is equal to uid from posts collection.
StreamBuilder(
stream: Firestore.instance
.collection('Posts')
.orderBy('date', descending: true)
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
const Text('Loading...');
} else {
return ListView.builder(
physics:
NeverScrollableScrollPhysics(),
shrinkWrap: true,
scrollDirection: Axis.vertical,
itemCount: snapshot
.data.documents.length,
itemBuilder: (context, index) {
DocumentSnapshot mypost =
snapshot
.data.documents[index];
return Stack(
children: <Widget>[
Container(
decoration:
BoxDecoration(
borderRadius:
BorderRadius
.circular(
15.0),
),
child: Padding(
padding:
EdgeInsets
.all(8.0),
child: Column(
children: <
Widget>[
StreamBuilder(
stream: Firestore.instance
.collection('users')
.where('uid', isEqualTo: mypost['uid'])
.snapshots(),
builder: (context, snapshot){
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return SizedBox();
case ConnectionState.active:
default:
break;
}
if (snapshot.hasError) print(snapshot.error);
DocumentSnapshot user = snapshot.data.documents[0];
return InkWell(
child: Row(
children: <
Widget>[
Container(
width:
32.0,
height:
32.0,
decoration: BoxDecoration(shape: BoxShape.circle, image: DecorationImage(fit: BoxFit.fill, image: NetworkImage(
// user image url
'${user['uimg']}')))),
SizedBox(
width:
10.0,
),
Text(
'${user['name']}',
style: TextStyle(
color: Colors.white,
fontSize: 12.0,
fontWeight: FontWeight.bold,
fontFamily: 'BalooDa2'),
),
],
),
);
},
),
Padding(
padding:
EdgeInsets.all(
5.0),
child: Text(
'${mypost['text']}',
style: TextStyle(
color: Colors
.white,
fontSize:
16.0,
fontFamily:
'Tajawal',
height:
1.3),
textAlign:
TextAlign
.justify,
textDirection:
TextDirection.rtl),
),
],
),
),
),
],
);
});
}
return Container(
height: 0.0,
width: 0.0,
);
},
),
I am building a Flutter app and I have a screen with 2 ListViews. The data source is a firestore database and it is the same for both list however one list presents only an image while the other list presents the image PLUS other information.
I have managed to found a solution to display both List however it does not seem the most effective because I believe I am downloading the same data 2 time. Do you have any suggestion on how to make it better???
See my code below
final _firestore = Firestore.instance;
class ItemPage extends StatefulWidget {
#override
_ItemPageState createState() => _ItemPageState();
}
class _ItemPageState extends State<ItemPage> {
bool showSpinner = false;
#override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
heroTag: 'itemppage',
transitionBetweenRoutes: false,
middle: Text(
appData.categoryName,
style: kSendButtonTextStyle,
),
),
child: Scaffold(
backgroundColor: kColorPrimary,
body: ModalProgressHUD(
inAsyncCall: showSpinner,
child: Column(
children: <Widget>[
Expanded(
child: ItemList(),
),
Container(
height: 80.0,
child: ItemListBottomScroll(),
)
],
),
),
),
);
}
}
class ItemList extends StatelessWidget {
#override
Widget build(BuildContext context) {
return StreamBuilder<QuerySnapshot>(
stream: _firestore
.collection('books')
.snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError) return new Text('Error: ${snapshot.error}');
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return new Text(
'Loading...',
style: kSendButtonTextStyle,
);
default:
return new PageView(
scrollDirection: Axis.horizontal,
children:
snapshot.data.documents.map((DocumentSnapshot document) {
return SingleChildScrollView(
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.all(10.0),
child: Stack(
children: <Widget>[
CachedNetworkImage(
imageUrl: document['url'],
placeholder: (context, url) =>
new CircularProgressIndicator(),
errorWidget: (context, url, error) =>
new Icon(Icons.error),
width: MediaQuery.of(context).size.width - 20,
height:
(MediaQuery.of(context).size.width - 20),
fit: BoxFit.cover),
Positioned(
bottom: 0.0,
right: 0.0,
child: IconButton(
color: kColorAccent.withOpacity(0.8),
iconSize: 50.0,
icon: Icon(Icons.add_circle),
onPressed: () {
print(document['name'] +
document.documentID +
' clicked');
},
),
),
],
),
),
Padding(
padding: const EdgeInsets.only(
left: 10.0, right: 10.0, bottom: 10.0),
child: Row(
children: <Widget>[
Expanded(
child: Text(
document['name'],
style: kSendButtonTextStyle,
),
flex: 3,
),
Expanded(
child: Text(
appData.currency + document['price'],
textAlign: TextAlign.right,
style: kDescriptionTextStyle,
),
flex: 1,
),
],
),
),
Padding(
padding: const EdgeInsets.only(left: 10.0, right: 10.0),
child: Container(
child: Text(
document['description'],
style: kDescriptionTextStyle,
),
width: double.infinity,
),
)
],
),
);
}).toList(),
);
}
},
);
}
}
class ItemListBottomScroll extends StatelessWidget {
#override
Widget build(BuildContext context) {
return StreamBuilder<QuerySnapshot>(
stream: _firestore
.collection('books')
.snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError) return new Text('Error: ${snapshot.error}');
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return new Text('Loading...');
default:
return new ListView(
scrollDirection: Axis.horizontal,
children:
snapshot.data.documents.map((DocumentSnapshot document) {
return Stack(
children: <Widget>[
Container(
height: 80.0,
width: 90.0,
padding: EdgeInsets.only(left: 10.0),
child: GestureDetector(
onTap: () {
print(document['name'] +
document.documentID +
' bottom clicked');
},
child: new CachedNetworkImage(
imageUrl: document['url'],
placeholder: (context, url) =>
new CircularProgressIndicator(),
errorWidget: (context, url, error) =>
new Icon(Icons.error),
fit: BoxFit.cover),
),
),
],
);
}).toList(),
);
}
},
);
}
}
In order to read both info from the same Stream you need to expose it as a broadcast stream first:
final streamQuery = _firestore
.collection('books')
.snapshots()
.asBroadcastStream();
return StreamBuilder<QuerySnapshot>(
stream: streamQuery,
builder: ...