I my app user are going to create by TextForm Field a collection into FIrestore and this collection has some documents. Into my StreamBuilder I have set up stream and I can get the documents but I cant retrieve the Number of the documents created by the user logged with snapshot.data.lenght which I get the error:
Class 'DocumentSnapshot' has no instance getter 'lenght'.
Receiver: Instance of 'DocumentSnapshot'
Tried calling: lenght
The code:
class CollectData extends StatefulWidget {
@override
_CollectDataState createState() => _CollectDataState();
}
class _CollectDataState extends State<CollectData> {
final String phone;
final String wife;
final String location;
_CollectDataState({this.phone, this.wife, this.location,});
Stream<DocumentSnapshot> getDatabase() async* {
FirebaseUser user = await FirebaseAuth.instance.currentUser();
yield* Firestore.instance
.collection('dataCollection')
.document(user.uid)
.snapshots();
}
@override
Widget build(BuildContext context,) {
return StreamBuilder(
stream: getDatabase(),
builder: (context, snapshot,) {
if (snapshot.data != null) {
return Column(
children: <Widget>[
Container(
height: 500,
child: ListView.builder(
shrinkWrap: true,
itemCount: snapshot.data.lenght,
itemBuilder: (BuildContext context, int) {
return Card(
color: Color(0xFF1f2032),
elevation: 15,
child: Container(
width: 60,
height: 60,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Card(
color: Color(0xfffeaf0d),
child: Container(
height: 40,
width: 40,
child: Icon(
Icons.contacts,
color: Colors.white,
size: 25,
)),
),
Text(
snapshot.data['phone'],
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold),
),
],
),
),
);
},
),
),
],
);
} else
return NoData();
},
);
}
}