0

Here is my attempt

In my Controller I have this

class UserController extends GetxController {
  final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;

  var _proo;
  get prooo => _proo;

  Future<Member?> readProfile() async {
       _proo = FireStoreHelper().fFetch("users", "user1");
  }

}

In my FireStoreHelper I have this

class FireStoreHelper {

  fFetch(collection, doc) {
    final docMember =
        FirebaseFirestore.instance.collection(collection).doc(doc);
    var query = docMember.get();
    return query;
  }

This is my Model

class Member {
 
  final String? username;
  //...others
  Member({

    this.username,
  //...others
  });


  static Member fromJson(Map<String, dynamic> json) => Member(
     
        username: json['username'],
        //...others
      );
}

Then in my UI I have this

   Get.lazyPut(() => UserController().readProfile());

    return GetBuilder<UserController>(builder: (userController) {

   //.......

 Text(userController.prooo.username),

}

Actually what am trying get a username of user1 as seen in the Image below

enter image description here

Please help me, I am new to this.

Tpp
  • 159
  • 7
  • Perhaps, this [answer](https://stackoverflow.com/questions/53517382/query-a-single-document-from-firestore-in-flutter-cloud-firestore-plugin/53517760#53517760) will help. – Alex Mamo Sep 24 '22 at 13:11

1 Answers1

1

try this one...

fFetch(collection, doc) async {

    final docMember = await
       FirebaseFirestore.instance.collection(collection).doc(doc).get();

    return docMember;

}


static Future<Member?> readProfile() async {

    _proo = await FireStoreHelper().fFetch("users", "user1");

    Member member = Member.fromJson(_proo);

    return member;

}
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 28 '22 at 18:51