Firebase Get All Documents does not work properly

Viewed 32

I'm at the very beginning of my flutter career. Right now, I'm facing a problem. I think it is because I don't really know the calling order of flutter codes.

The problem is when I start the application, (by saving all files), I see the first ScreenShot but while the application working and without changing any code I enter CTRL+S on the dart file and I see the second screen finally. Why I cannot access the second screen directly?

*The structure is basically getting all the documents in a collection and list them in grid view.

final CollectionReference sebzeCollection =
    Firestore.instance.collection('sebzeler');

class RightBody extends StatefulWidget {
  @override
  _RightBodyState createState() => _RightBodyState();
}

class _RightBodyState extends State<RightBody>
    with AutomaticKeepAliveClientMixin {
  @override
  void initState() {
    getAllSebze();

    super.initState();
  }

  List<SebzeMeyve> sebzeler;

  getAllSebze() async {
    sebzeler = new List<SebzeMeyve>();
    sebzeCollection.getDocuments().then((QuerySnapshot snapshot) {
      snapshot.documents.forEach((DocumentSnapshot doc) {
        SebzeMeyve sebze = new SebzeMeyve(
            isInSale: doc.data['isInSale'],
            organic: doc.data['organik'],
            dogal: doc.data['dogal'],
            fiyat: doc.data['fiyat'],
            mensei: doc.data['mensei'],
            name: doc.data['name'],
            picture: doc.data['picture'],
            stok: doc.data['stok']);
        sebzeler.add(sebze);
      });
    });
  }

  List<Widget> _setBuildCards() {
    List _listings = new List<Widget>();
    for (int i = 0; i < sebzeler.length; i++) {
      _listings.add(_buildCard(
          'T-shirt',
          sebzeler[i].name.toUpperCase(),
          '\₺' + sebzeler[i].fiyat,
          sebzeler[i].picture,
          false,
          false,
          context));
    }
    return _listings;
  }
  @override
  Widget build(BuildContext context) {
    // List<SebzeMeyve> _sebzeler = widget.test;
    //super.build(context);
    return Padding(
        padding: const EdgeInsets.only(top: 10.0),
        child: Container(
          padding: EdgeInsets.only(left: 15, right: 15.0),
          width: MediaQuery.of(context).size.width - 30,
          height: MediaQuery.of(context).size.height - 50,
          child: GridView.count(
            crossAxisCount: 3,
            children: _setBuildCards(),
          ),
        ));
  }

First ScreenShot

Second ScreenShot

Thank you!

0 Answers
Related