Home > other >  How to fix this Instance member 'getCategoryModelList' can't be accessed using static
How to fix this Instance member 'getCategoryModelList' can't be accessed using static

Time:01-02

class AppProvider with ChangeNotifier {
  static List<CategoryModel> categoryModelList = [];
  late CategoryModel categoryModel;
  Future<void> getCategoryProduct() async {
    List<CategoryModel> list = [];
    QuerySnapshot querySnapshot =
        await FirebaseFirestore.instance.collection("homecategory").get();
    querySnapshot.docs.forEach(
      (categoryData) {
        categoryModel = CategoryModel(
          image: categoryData["image"],
          name: categoryData["name"],
        );
        list.add(categoryModel);
      },
    );
    categoryModelList = list;
    notifyListeners();
  }

  List<CategoryModel> get getCategoryModelList {
    return categoryModelList;
  }
}

Widget _buildBottomPart() {
return Container(
  width: double.infinity,
  height: 240,
  child: Column(
    mainAxisAlignment: MainAxisAlignment.end,
    crossAxisAlignment: CrossAxisAlignment.start,
    children: [
      Container(
        height: 240,
        child: ListView.builder(
          scrollDirection: Axis.horizontal,
          itemCount: AppProvider.getCategoryModelList.length,
          itemBuilder: (ctx, index) => _buildSingleCategory(
            name: AppProvider.getCategoryModelList[index].name,
            image: AppProvider.getCategoryModelList[index].image,
          ),
        ),
      ),
    ],
  ),
);
}

CodePudding user response:

either create an instance from AppProvider like this:

AppProvider appProvider = AppProvider();
appProvider.getCategoryModelList.length

or define 'getCategoryModelList' as static List

  • Related