Flutter:如何从Firestore检索对象?

时间:2018-09-14 05:47:59

标签: flutter google-cloud-firestore

enter image description here

屏幕截图中的分数是一个对象,其中包含用户的分数,后跟用户ID ...如何获取该值

我在班上的代码是

class Alllist {
  final  String category, imageUrl, listcategory,title,id,userid,userimage,content,username,type,useremail,topictype,
      lessonlang,lessontype,lessonid;
  final Map score;
  final int comments,seenby;
  final bool seen;


  Alllist(
      {
        this.category,
        this.imageUrl,
        this.listcategory,
        this.title,
        this.topictype,
        this.username,
        this.useremail,
        this.comments,this.content,this.userimage,this.userid,this.seenby,this.id,this.type,this.lessonlang,
      this.lessontype,this.lessonid,this.seen,this.score});

  Alllist.fromDocument(DocumentSnapshot document)
      :
//        progress = document["Progress"],
        topictype = document["Topic type"],
        category = document[""],
        imageUrl = document["url"],
        score = document["score"],
        listcategory = document["listcategory"],
        title = document["title"],
        comments = document["comments"],
        content = document["Content"],
        seenby = document["seenby"],
        userimage = document["userimage"],
        userid = document["userid"],
        id= document[""],
        username=document["username"],
        type=document["type"],
        lessonlang=document["lesson language"],
        lessontype=document["lesson type"],
        lessonid=document["lessonId"],
        seen=document["Seenstatus"],
        useremail= document[" userEmail"];
}

我尝试检索的代码

Widget buildGridItem(Alllist alllist,index) {
    return  widget.intp==0?
    InkWell(
      child:  Card(
        child: Stack(
          children: <Widget>[
            Padding(padding: EdgeInsets.all(7.0),
            child: new Container(
              child: new AnimatedCircularChart(
                key: index==0?_chartKey:index==1?_chartKey1:null,
                size: _chartSize,
                initialChartData:_generateChartData(alllist.score),
                chartType: CircularChartType.Radial,
                edgeStyle: SegmentEdgeStyle.round,
                percentageValues: true,
                holeRadius: 38.0,
              ),
              width: 80.0,
              height: 80.0,
              decoration: new BoxDecoration(
                shape: BoxShape.circle,
                border: Border.all(color: Colors.blue,width: 1.0,style: BorderStyle.solid,),
                image: new DecorationImage(
                    fit: BoxFit.fill,
                    image: new NetworkImage(
                        alllist.imageUrl)),
              ),
              margin: const EdgeInsets.symmetric(horizontal: 20.0),
//                      child: Text(name),
            ),),


            Positioned(child:Center(
                child: Text(alllist.title,style: TextStyle(fontWeight: FontWeight.bold,color: Colors.blueGrey),)),
              bottom: 1.0,left: 20.0,right: 20.0,top: 85.0,
            ),
//          Padding(padding: EdgeInsets.only(top: 80.0,left: 10.0),
//            child: Text(alllist.title,style: TextStyle(fontWeight: FontWeight.bold,color: Colors.blueGrey),),
//          ),
          ],
        ),
      ),

0 个答案:

没有答案