I'm trying to get data from the firebase database. I'm getting this error:
The operator '[]' isn't defined for the class 'Object'
Try many methods but the error is still here.
StreamBuilder<QuerySnapshot>(
stream: _categoryProvider.category.snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot){
if(snapshot.hasError){
return Text('Something went wrong..');
}
if(snapshot.connectionState == ConnectionState.waiting){
return Center(child: CircularProgressIndicator(),);
}
return Expanded(
child: ListView(
children: snapshot.data.docs.map((DocumentSnapshot document){
return ListTile(
leading: CircleAvatar(
backgroundImage: NetworkImage(document?.data()['image']),// error is on this line
),
//title: Text(document.data()['category name']),
onTap: (){},
);
}).toList(),
),
);
}),
Here is CategoryProvider.
import 'package:cloud_firestore/cloud_firestore.dart';
class CategoryProvider{
CollectionReference category = FirebaseFirestore.instance.collection('categories');
}