0

I don't know how to do it. It's not working at the moment. The 'Future' function is very confusing me.

Future<void> createUser(String userId, String name, String surname, String email, String role, String imageUrl) async {
try {
  var token = await messagingService.getToken();
  return await db.collection(CommonFirebaseRemoteDataSource.usersCollectionName).doc(userId).set({
    "name": name,
    "surname": surname,
    "email": email,
    "image": imageUrl,
    "lastSeen": DateTime.now().toUtc(),
    "role": role,
    "tokens": [token],
    "quizes": []
  });
} catch (e) {
  print(e);
}

}

serbox
  • 1
  • Hi @serbox, welcome to Stack Overflow. Could you add more details on your issue on what you're trying to achieve and the behavior that you're expecting? Being specific and detailed helps. It'll be also helpful if you could provide the error logs that you're getting (if there's any). These details will help your question to get more likely answered. – Omatt Feb 16 '22 at 08:10
  • Your question is quite confusing... but try to remove the return on your try statement since you set the function to **Future** which is expecting no returns... – Kei Credo Feb 16 '22 at 08:13
  • Does this answer your question? [What is a Future and how do I use it?](https://stackoverflow.com/questions/63017280/what-is-a-future-and-how-do-i-use-it) – nvoigt Feb 16 '22 at 08:17
  • I think you are asking about unit testing or widget testing async code. If so, I wrote an article about this a while ago: https://manichord.com/blog/posts/testing-times.html and there are others on this topic too, it all really comes down to using FakeAsync really: https://medium.com/flutter/understanding-async-in-flutter-tests-a304a7604b3c – Maks Feb 17 '22 at 06:18

0 Answers0