Firebaseのデータを関数を読んで返したいのですがjava.lang.IllegalStateException: Task is not yet complete
がでてうまく動きません。
どうすればFirebaseのデータだけ返却できますか?
UserRepo側
Kotlin
1fun getUser(userId: String): User? { 2 var data: User? = null 3 userRef.document(userId).get().addOnSuccessListener { documentSnapshot -> 4 if (documentSnapshot.exists()) { 5 data = documentSnapshot.toObject(User::class.java) 6 } 7 } 8 return data 9 }
activity側
Koltin
1val userData = UserRepository.getUser(user.uid)
回答1件
あなたの回答
tips
プレビュー