No data retrieved for specific collection Firebase


I am new to Flutter and I am trying to build a food delivery app.
I managed to load the categories from Firebase using a provider, but the exact same code wont work for my restaurants.
Basically, the list of restaurants retrieved is null. It gives me no errors, just that.

this is Restaurant Model

class RestaurantModel{
  static const NAME = "name";
  static const ID = "id";
  static const AVG_PRICE = "avgPrice";
  static const RATING = "rating";
  static const RATES = "rates";
  static const IMAGE = "image";
  static const POPULAR = "popular";

  int _id;
  String _name;
  double _avgPrice;
  double _rating;
  String _image;
  bool _popular;
  int _rates;


  int get id => _id;
  String get name => _name;
  double get avgPrice => _avgPrice;
  double get rating => _rating;
  String get image => _image;
  bool get popular => _popular;
  int get rates => _rates;

  RestaurantModel.fromSnapshot(DocumentSnapshot snapshot){
    _id =[ID];
    _name =[NAME];
    _avgPrice =[AVG_PRICE];
    _rating =[RATING];
    _image =[IMAGE];
    _popular =[POPULAR];
    _rates =[RATES];



Restaurant services

    class RestaurantServices {

  String collection = "restaurants";
  FirebaseFirestore _firestore = FirebaseFirestore.instance;

  Future<List<RestaurantModel>> getRestaurants() async => _firestore.collection(collection).get().then((result){
    List<RestaurantModel> restaurants = [];
    for (DocumentSnapshot restaurant in {

    return restaurants;


And Restaurant Provider

class RestaurantProvider with ChangeNotifier{

  RestaurantServices _restaurantServices = RestaurantServices();
  List<RestaurantModel> restaurants = [];


  _loadRestaurants() async {

    restaurants = await _restaurantServices.getRestaurants();




Future<List> is return only the FutureOr so we only need to wait and get the value from the async function like below

 await _restaurantServices.getRestaurants().then((value){
      restaurants = value;

I hope it will help you to achieve your requirement.

Answered By – Balasubramani Sundaram

Answer Checked By – David Goodson (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.