Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter Flatter cloud firestore StreamBuilder<;文档快照>;错误_Flutter_Dart_Google Cloud Firestore - Fatal编程技术网

Flutter Flatter cloud firestore StreamBuilder<;文档快照>;错误

Flutter Flatter cloud firestore StreamBuilder<;文档快照>;错误,flutter,dart,google-cloud-firestore,Flutter,Dart,Google Cloud Firestore,在更新了我的flatter插件之后,我不得不更新我的代码,因为我收到了这样的错误:“Firestore”已被弃用,不应该被使用。类Firestore已弃用,请改用“FirebaseFirestore” 我遵循了警告并更新了代码,但现在我的streamBuilders中有一个无法工作 我不知道为什么 这是我的密码 class PickupLayout extends StatelessWidget { final Widget scaffold; final CallMethods cal

在更新了我的flatter插件之后,我不得不更新我的代码,因为我收到了这样的错误:“Firestore”已被弃用,不应该被使用。类Firestore已弃用,请改用“FirebaseFirestore”

我遵循了警告并更新了代码,但现在我的streamBuilders中有一个无法工作 我不知道为什么

这是我的密码

class PickupLayout extends StatelessWidget {


final Widget scaffold;
  final CallMethods callMethods = CallMethods();

  PickupLayout({
    @required this.scaffold,
  });

  @override
  Widget build(BuildContext context) {
    final UserProvider userProvider = Provider.of<UserProvider>(context);

return (userProvider != null && userProvider.getUser != null)
    ? StreamBuilder<DocumentSnapshot>(
        stream: callMethods.callStream(uid: userProvider.getUser.uid),
        builder: (context, snapshot) {
          if (snapshot.hasData && snapshot.data.data != null) {
            Call call = Call.fromMap(snapshot.data.data());

            if (!call.hasDialled) {
              return PickupScreen(call: call);
            }
          }
          return scaffold;
        },
      )
    : Scaffold(
        body: Center(
          child: CircularProgressIndicator(),
        ),
      );
  }
}
类PickupLayout扩展了无状态小部件{
最终支架;
final CallMethods CallMethods=CallMethods();
拾取布局({
@需要这个脚手架,
});
@凌驾
小部件构建(构建上下文){
最终用户提供者UserProvider=Provider.of(上下文);
返回(userProvider!=null&&userProvider.getUser!=null)
?StreamBuilder(
流:callMethods.callStream(uid:userProvider.getUser.uid),
生成器:(上下文,快照){
if(snapshot.hasData&&snapshot.data.data!=null){
Call Call=Call.fromMap(snapshot.data.data());
如果(!call.hasDialled){
返回拾取屏幕(呼叫:呼叫);
}
}
返回脚手架;
},
)
:脚手架(
正文:中(
子对象:CircularProgressIndicator(),
),
);
}
}
这里是错误

════════ Exception caught by widgets library ═══════════════════════════════════
The following NoSuchMethodError was thrown building StreamBuilder<DocumentSnapshot>(dirty, state: _StreamBuilderBaseState<DocumentSnapshot, AsyncSnapshot<DocumentSnapshot>>#a2802):
The method '[]' was called on null.
Receiver: null
Tried calling: []("caller_id")
The relevant error-causing widget was
StreamBuilder<DocumentSnapshot>
package:vdb_tinus_app/…/pickup/pickup_layout.dart:22
When the exception was thrown, this was the stack
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1      new Call.fromMap
package:vdb_tinus_app/…/models/call.dart:37
#2      PickupLayout.build.<anonymous closure>
package:vdb_tinus_app/…/pickup/pickup_layout.dart:26
#3      StreamBuilder.build
package:flutter/…/widgets/async.dart:525
#4      _StreamBuilderBaseState.build
════════ widgets库捕获到异常═══════════════════════════════════
生成StreamBuilder时引发了以下NoSuchMethodError(脏,状态:_StreamBuilderBaseState#a2802):
对null调用了方法“[]”。
收件人:空
已尝试呼叫:[”(“呼叫者id”)
导致错误的相关小部件已被删除
StreamBuilder
包装:vdb_tinus_应用程序/../pickup/pickup_布局。省道:22
当抛出异常时,这是堆栈
#0 Object.noSuchMethod(省道:核心补片/对象补片。省道:51:5)
#1新的Call.fromMap
包装:vdb_tinus_应用程序/../models/call.dart:37
#2 PickupLayout.build。
包装:vdb_tinus_应用程序/../pickup/pickup_布局。省道:26
#3.StreamBuilder.build
包:flatter/../widgets/async.dart:525
#4_StreamBuilderBaseState.build
这是在更新我的云firestore plung之前根据日志显示的错误行,它过去看起来像这样
if(snapshot.hasData&&snapshot.data.data!=null){Call Call=Call.fromMap(snapshot.data.data);
更新后,我必须将其更改为
if(snapshot.hasData&&snapshot.data.data!=null){Call Call=Call.fromMap(snapshot.data.data());

在这一行中,
如果(snapshot.hasData&&snapshot.data.data!=null){
,您正在检查
DocumentSnapshot.data
是否为null。因为它是一个函数(因此是一个对象),您的比较结果永远不会计算为
false

在下一行中,
snapshot.data.data()
,您正在调用上述函数,在本部分中,该函数的返回值很可能是
null

          if (snapshot.hasData && snapshot.data.data != null) {
        Call call = Call.fromMap(snapshot.data.data());

        if (!call.hasDialled) {
          return PickupScreen(call: call);
        }
      }
你应该像那样使用这个部件

if (snapshot.hasData && snapshot.data.data() != null) {

除了这个项目,如果你是新手,你不应该尝试制作视频通话应用程序。我知道你从视频中获取了这个代码

这个错误具体指的是哪一行代码?请编辑这个问题以明确什么没有按照你的预期工作。我是新手,请详细说明我的想法不行