I am trying to get several details from the collection "users" (eg, name, surname, nickname) stored in Firestore with the function getUserData() to pass them to other classes through the constructor. The parenthesis in getUserData() is highlighted, pointing to this error message:
1 positional argument expected by 'getUserData', but 0 found.
If I put name as getUserData(name), it says Undefined name 'name'.
What am I missing here?
class AuthWrapper extends StatelessWidget { const AuthWrapper({super.key}); @override Widget build(BuildContext context) { return StreamBuilder<User?>( stream: FirebaseAuth.instance.authStateChanges(), builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { return const CircularProgressIndicator(); } else if (snapshot.hasData && snapshot.data != null) { String eMail = snapshot.data!.email.toString(); String Name = getUserData().toString(); // 👈 PROBLEM HERE return AnApp(forUser1: eMail, forUser2: Name); } else { return const LogIn(); } }, ); } } Future<void> getUserData(String name) async { User? user = FirebaseAuth.instance.currentUser; if (user != null) { DocumentSnapshot<Map<String, dynamic>> snapShot = await FirebaseFirestore.instance.collection('users').doc(user.uid).get(); if (snapShot.exists) { var datA = snapShot.data(); String name = datA?['name']; String surname = datA?['surname']; String nickname = datA?['nickname']; } } }