0

i want to retrieve data from firestore that has about 8000 docs, i have created method to get the docs data in a list then i created ListView to display my items but nothing showed...i created the same technique in other collections that has less docs like around 50 docs and it always works. so i don't know is the main problem is retrieving a large amount of docs ?

my code:

class FoodDetailsModel{
  late String name; late String caffeine; late String calcium;


  FoodDetailsModel({
    required this.name, required this.caffeine, required this.calcium,

  });

  FoodDetailsModel.fromJson(dynamic json)
  {
    name=json['name'];name=json['caffeine'];name=json['calcium'];

  }
  dynamic toMap()
  {
    return {
      'name':name, 'caffeine':caffeine, 'calcium':calcium,

    };
  }
}




void getFoodDetails()
{
  FirebaseFirestore.instance
      .collection('nutrition')
      .get()
      .then((value){
        foodDetailsList = [];
        value.docs.forEach((element)
        {
          foodDetailsList.add(FoodDetailsModel.fromJson(element.data()));
        });
        emit(getFoodDetailsSuccussState());
  });
}







class FoodDetailsScreen extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return BlocConsumer<NutritionCubit,LifeStates>(
      listener: (context,state){},
      builder: (context,state)
      {
        NutritionCubit.get(context).getFoodDetails();
        return  Scaffold(
          appBar: AppBar(
            title: Text('Diets'),
          ),
          body: Column(
            children: [
              ListView.separated(
                  itemBuilder: (context,index) => buildFoodDetails(context,NutritionCubit.get(context).foodDetailsList[index]),
                  itemCount: NutritionCubit.get(context).foodDetailsList.length,
                separatorBuilder: (BuildContext context, int index) => SizedBox(height: 20,),
              ),
            ],
          )
        );
      },
    );
  }
}

Widget buildFoodDetails(context,FoodDetailsModel model)
{
  return Text(model.name);
}

how can i solve that ?

hazem saad
  • 107
  • 5

1 Answers1

1

You can narrow down the issue by debugging and checking to see if you are actually getting any data from firestore. I would have a look at your fromJson, as it does not have a return method. I suggest taking a look here on how to set up withConverter properly: Flutter Expandable Grouped Listview

You can then check to see if your BlocConsumer actually retrieves the data by breakpointing in your ListView.

If you see the data in your ListView via a debugger, it might be an error with the way you are presenting the data.

If you have narrowed down where the problem presents, you can try and find the issue from there.