【问题标题】:I am getting error in my DataSnapShot in getuserinformation我在 getuserinformation 中的 DataSnapShot 中遇到错误
【发布时间】:2021-12-28 12:36:51
【问题描述】:

这里是代码

     static void getCurrentOnlineUserInformation()async{
  User user = _firebaseAuth.currentUser;
  String userid = user.uid;
  DatabaseReference reference = FirebaseDatabase.instance.ref().child('userProfile');
  reference.child(userid).once().then((DataSnapshot dataSnapshot){
  }
  );
  }

但它没有获取 DataSnapShot

错误 错误:无法将参数类型“Null Function(DataSnapshot)”分配给参数类型“FutureOr Function(DatabaseEvent)”。 (argument_type_not_assignable 在 [themovers] lib\assistants\assistantmethods.dart:86)

它一次又一次地获得空值

here is live code error

here is database

here is the model

【问题讨论】:

    标签: android ios flutter dart snapshot


    【解决方案1】:

    默认情况下 .then 接受动态 parameter 但如果您希望传递不同的 parameter 则您可以将 Function(dynamic) 更改为 Function(YOURTYPE) 尝试以下代码:

    static void getCurrentOnlineUserInformation()async{
      User user = _firebaseAuth.currentUser;
      String userid = user.uid;
      DatabaseReference reference = 
            FirebaseDatabase.instance.ref().child('userProfile');
             reference.child(userid).once().then(<DataSnapshot>(DataSnapshot dataSnapshot){
            }
          );
      }
    

    【讨论】:

    • 再次出现同样的错误并立即显示此栏 参数类型“Null Function(DataSnapshot)”无法分配给参数类型“FutureOr Function(DatabaseEvent)”
    猜你喜欢
    • 2011-07-06
    • 2017-01-02
    • 1970-01-01
    • 2019-01-23
    • 1970-01-01
    • 2012-04-24
    • 2015-07-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多