0

i wanna add a data.value() from Firebase Firestore items in a List,

i got 10 Item in Firestore Array, and all items will be showed in List ,

here im getting the Doc as ,

docCek() {
    firestoreInstance.collection("icerik").doc("TYT").get().then((value) {
      //print(value.data());
      int itemCount = value.data()!["dersler"].length;
    });

    update();
  }

result is :

I/flutter (11270): [Türkce, Matematik, Geometri, Fizik, Kimya, Biyoloji, Tarih, Cografya, Felsefe, Din Kültürü]

and i got a Local RxList , i wanna add all items in List with for , but for Loop is not going ,

  var dersler = [].obs;

and my Function with For Loop

   docCek() {
    firestoreInstance.collection("icerik").doc("TYT").get().then((value) {
      //print(value.data());

      print(value.data()!["dersler"]);
      print(value.data()!["dersler"].length);

      int count = value.data()!["dersler"].length;

      for (var i = 0; i >= count; i++) {
        dersler.add(value.data()!["TYT"]);
        print(dersler.toString());
      }
    });

    update();
  }

how can i add all items from result to dersler List ?

Thanks !

3
  • 1
    I think your for loop has inverted logic. Your condition is true for values of i that larger than count. Try for (var i = 0; i < count; i++) { Commented Dec 2, 2021 at 22:57
  • Waow Nice its working right now ! :D But only null,null,null ! Commented Dec 2, 2021 at 23:12
  • 1
    I don't know what your data structure looks like, but I suspect you are calling the wrong key in dersler.add(value.data()!["TYT"]);. Is TYT the correct key? Commented Dec 2, 2021 at 23:16

1 Answer 1

1

I got it right now, i add only addAll Function and here is the new Code ,

 docCek() {
    firestoreInstance.collection("icerik").doc("TYT").get().then((value) {
      //print(value.data());

      print(value.data()!["dersler"]);
      print(value.data()!["dersler"].length);

      int count = value.data()!["dersler"].length;

      dersler.addAll(value.data()!["dersler"].toList());

      /*  for (var i = 0; count > i; i++) {
        dersler.addAll(value.data()!["dersler"].toString());
        print(dersler.toString());
     }*/
    });

    update();
  }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.