我需要检索与Firebase中特定文档相关的所有字段。该怎么办? 我在下面附加了我的代码。
return new Text(snapshot.data['brand']);
但是我需要检索它们而不需要通过键调用。 有什么办法可以将所有数据检索到map或var中? 请帮我解决这个问题
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
class ItemView extends StatefulWidget {
final String docID123;
const ItemView({ this.docID123}) ;
@override
_ItemViewState createState() => _ItemViewState();
}
String name123;
class _ItemViewState extends State<ItemView> {
@override
//String docuID = Widget.documentid;
Widget build(BuildContext context) {
//final Map<String, Object>rcvdData = ModalRoute.of(context).settings.arguments;
//docID = ${rcvdData['docuID'];}
//String name123 = rcvdData[0];
return Scaffold(
appBar: AppBar(
title: Text('Item Data'),
),
body: ListView(
children: <Widget>[
Text(widget.docID123),
getItems(),
],
),
);
}
}
Widget getItems(){
return StreamBuilder(
//1597917013710
stream: Firestore.instance.collection('ads').document('1597917013710').snapshots(),
builder: (context, snapshot){
if (!snapshot.hasData) {
//snapshot.data.toString();
return new Text("Loading");
}
var userDocument = snapshot.data;
String myname = snapshot.data.map.toString();
//return new Text(snapshot.data['brand']);
return new Text(myname);
}
);
}
Future getCatagory() async {
var firestone = Firestore.instance;
QuerySnapshot alldata = await firestone.collection("catagory_names/Vehicles").getDocuments();
for(int i=0;i<alldata.documents.length;i++){
DocumentSnapshot snap = alldata.documents[i];
}
return Text('12345');
}