0

I used this code in the past in my project and it was work perfectly

    FirebaseAuth.instance.currentUser.then((user) {
  FirebaseFirestore.instance.collection('todos').doc().set({
    'body': theController.text,
    'done': false,
    'user_id': user.uid,
    'time': DateTime.now().toString(),
  });
}).then((value) {
  Navigator.of(context).pop();
  theController.clear();
});

But now it's Not Accept ".then" the Error is "The method 'then' isn't defined for the type 'User"

Ali Max
  • 91
  • 3

1 Answers1

0

If you have a read of the Firebase Auth Changelog, you will see the following breaking change:

BREAKING: Accessing the current user via currentUser() is now synchronous via the currentUser getter.

Which means it no longer returns a Future, but the user object directly. This means you can simplify your code:

final user = FirebaseAuth.instance.currentUser;
FirebaseFirestore.instance.collection('todos').doc().set({
  'body': theController.text,
  'done': false,
  'user_id': user.uid,   'time': DateTime.now().toString(),
}).then((value) {
  Navigator.of(context).pop();
  theController.clear();
});
MichaelM
  • 5,518
  • 2
  • 30
  • 23