'Error: The getter 'uid' isn't defined for the class 'Future<FirebaseUser> Function()'
Solution 1:[1]
That's because you are using Future Function to get the current user, you can get the current user simply like this:
User teacher = FirebaseAuth.instance.currentUser!;
Solution 2:[2]
That happens because you are trying to access a future result when it's not ready yet.
As you see, your teacher variable is a Future<FirebaseUser>, so at that point moving fast machine speed you reach the access to teacher.uid before it's completed and still a promise.
On that line that you call the teacher, change from:
Future<FirebaseUser> Function() teacher = FirebaseAuth.instance.currentUser;
To this:
FirebaseUser teacher = FirebaseAuth.instance.currentUser!;
With this you code will wait until FirebaseAuth do all requests and return only the result.
You can look an example at https://github.com/FirebaseExtended/flutterfire/blob/8a2f512e6d52fa8e47ffc53e55b2593de61e2085/packages/firebase_auth/firebase_auth/example/lib/profile.dart#L34 Also at https://firebase.flutter.dev/docs/auth/usage
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | tareq albeesh |
| Solution 2 |
