Home > OS >  Instance member 'getPopularProductList' can't be accessed using static access
Instance member 'getPopularProductList' can't be accessed using static access

Time:05-09

I have been trying to called a method from another dart file from below file..but it's showing Instance member 'getPopularProductList' can't be accessed using static access.

import 'package:food_delivery/data/repository/popular_product_repo.dart'; import 'package:food_delivery/models/product_models.dart';

import 'package:get/get.dart';



class PopularProductController extends GetxController {
  final PopularProductRepo popularProductRepo;
  PopularProductController({required this.popularProductRepo});
   List<dynamic> _popularProductList = [];
   List<dynamic> get popularProductList =>_popularProductList;

  Future<void> getPopularProductList() async {
    Response response = await PopularProductRepo.getPopularProductList();
    if (response.statusCode == 200) {
      _popularProductList = [];
      _popularProductList.addAll(Product.fromJson(response.body).products);
      update();
    }
    else{

    }
  }

}

The method was defined below here..

    import 'package:food_delivery/data/api/api_client.dart';
import 'package:get/get.dart';

class PopularProductRepo extends GetxService {
  final ApiClient apiClient;popular_product_repo
  PopularProductRepo({required this.apiClient});

  Future<Response> getPopularProductList() async {
    return await apiClient.getData("http://mvs.bslmeiyu.com");
  }
}

CodePudding user response:

it's because PopularProductRepo.getPopularProductList() is the way you would access the method if it was defined as a static method, you want to use the instance of the class to access the method instead, so instead us popularProductRepo.getPopularProductList()

  • Related