DateTime不是TimeStamp类型的子类型/未处理的异常:无效的参数:'Future 的实例>

问题描述 投票:0回答:1

因此,我正在使用附近的连接A​​PI来发现我周围的设备并将其数据存储在firestore中,但是我不断收到2条警告,提示我从与用户接触的用户那里获得的位置以及与我接触的时间他们

这是两个警告:

1)DateTime不是TimeStamp类型的子类型

2)未处理的异常:无效的参数:Future <.locationdata>的实例当我尝试将这些值添加到Firestore时

这是我的发现方法:

void discovery() async {
    try {
      bool a = await Nearby().startDiscovery(loggedInUser.email, strategy,
          onEndpointFound: (id, name, serviceId) async {
        print('I saw id:$id with name:$name'); // the name here is an email

        var docRef =
            _firestore.collection('users').document(loggedInUser.email);

        //  When I discover someone I will see their email
        docRef.collection('met_with').document(name).setData({
          'email': await getUsernameOfEmail(email: name),
          'contact time': DateTime.now() as Timestamp ,
          'contact location': location.getLocation(),
        });
      }, onEndpointLost: (id) {
        print(id);
      });
      print('DISCOVERING: ${a.toString()}');                                                      
    } catch (e) {
      print(e);
    }
  }

这是另一种方法,可以从Firestore检索发现的信息:

void addContactsToList() async {
    await getCurrentUser();
    _firestore
        .collection('users')
        .document(loggedInUser.email)
        .collection('met_with')
        .snapshots()
        .listen((snapshot) {

   for (var doc in snapshot.documents) {
        String currEmail = doc.data['email'];
        DateTime currTime = doc.data.containsKey('contact time')
            ? (doc.data['contact time'] as Timestamp).toDate()
            : null;
        String currLocation = doc.data.containsKey('contact location')
            ? doc.data['contact location']
            : null;
        String _infection = doc.data['infected'];
        if (!contactTraces.contains(currEmail)) {
          contactTraces.add(currEmail);
          contactTimes.add(currTime);
          contactLocations.add(currLocation);
          infection.add(_infection);
        }
      }
      setState(() {});
      print(loggedInUser.email);
    });
  }

请对此进行任何修复吗?

所以我正在使用附近的连接A​​PI来发现我周围的设备并将其数据存储在Firestore中,但是我不断收到2条关于我从用户那里来的位置的警告...

firebase flutter timestamp location google-nearby-connections
1个回答
0
投票
使用异步函数将Future <.locationdata>转换为LocationData。
© www.soinside.com 2019 - 2024. All rights reserved.