I'm trying to retrieve those both values from FireStore
lastname "test" (string) name "Carlos" (String)
However I'm getting this error
*Another exception was thrown: NoSuchMethodError: Class 'QueryDocumentSnapshot' has no instance method '[]'. ═ Exception caught by widgets library ═ The following NoSuchMethodError was thrown building StreamBuilder<QuerySnapshot> (dirty, state: _StreamBuilderBaseState<QuerySnapshot, AsyncSnapshot<QuerySnapshot>>#e1fff): Class 'QueryDocumentSnapshot' has no instance method '[]'. Receiver: Instance of 'QueryDocumentSnapshot' Tried calling:[] ("name")
Here's my code:
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
class HomePage extends StatelessWidget{
List<Widget> makeListWiget(AsyncSnapshot snapshot){
return snapshot.data.documents.map<Widget>((document){
return ListTile(
title: Text(document["name"]),
subtitle: Text(document["lastname"]),
);
}).toList();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Área do Cliente'),
),
body: Container(
child: StreamBuilder (
stream: FirebaseFirestore.instance.collection("users").snapshots(),
builder: (context, snapshot){
return ListView(
children: makeListWiget(snapshot),
);
}
)
)
);
}
}