Firebase 类别';文档快照';没有实例方法';[]和#x27;。接收方:实例';文档快照';已尝试呼叫:[](“名称”)

Firebase 类别';文档快照';没有实例方法';[]和#x27;。接收方:实例';文档快照';已尝试呼叫:[](“名称”),firebase,flutter,google-cloud-firestore,stream,Firebase,Flutter,Google Cloud Firestore,Stream,我正在尝试创建一个小部件,您可以在其中查看其他人的个人资料。我已经设置了一个指向特定用户的文档引用流,但在尝试从字段检索数据时出错。在此之前,我将listbuilders与snapshot.data[index].data()一起用于集合查询,但我似乎找不到适合这种情况的格式 import 'package:flutter/material.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; class ForeignUs

我正在尝试创建一个小部件,您可以在其中查看其他人的个人资料。我已经设置了一个指向特定用户的文档引用流,但在尝试从字段检索数据时出错。在此之前,我将listbuilders与snapshot.data[index].data()一起用于集合查询,但我似乎找不到适合这种情况的格式

import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

class ForeignUserProfile extends StatefulWidget {


  final fuid;
  ForeignUserProfile({Key key, @required this.fuid}) : super(key: key);

  @override
  _ForeignUserProfileState createState() => _ForeignUserProfileState();
}

class _ForeignUserProfileState extends State<ForeignUserProfile> {


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('User Profile'),
      ),
      body: StreamBuilder(

        stream: FirebaseFirestore.instance.collection('userData').doc(widget.fuid).snapshots(),
        builder: (context, snapshot) {
          if(!snapshot.hasData){
            return Text('hol up');
          }
          else
          return Container(
            child: Text(snapshot.data['name'])
            
          );

        }
      )
    );
  }

导入“包装:颤振/材料.省道”;
导入“包:cloud_firestore/cloud_firestore.dart”;
类ForeignUserProfile扩展StatefulWidget{
最终fuid;
ForeignUserProfile({Key-Key,@required this.fuid}):super(Key:Key);
@凌驾
_ForeignUserProfileState createState()=>_ForeignUserProfileState();
}
类_ForeignUserProfileState扩展状态{
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:文本(“用户配置文件”),
),
正文:StreamBuilder(
流:FirebaseFirestore.instance.collection('userData').doc(widget.fuid).snapshots(),
生成器:(上下文,快照){
如果(!snapshot.hasData){
返回文本('holup');
}
其他的
返回容器(
子项:文本(snapshot.data['name'])
);
}
)
);
}

您使用的是什么版本的Flatter Firestore?查看,
0.14.1
实现了一项功能,向DocumentSnapshot添加一个
[]
操作符,充当
get()