[英]Need Help please ! How to fix this Instance member 'getCategoryModelList' can't be accessed using static access in flutter
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, ), ), ), ], ), );小部件_buildBottomPart(){返回容器(宽度:double.infinity,高度:240,孩子:列(mainAxisAlignment:MainAxisAlignment.end,crossAxisAlignment:CrossAxisAlignment.start,孩子:[容器(高度:240,孩子:ListView.builder(滚动方向) : Axis.horizontal, itemCount: AppProvider.getCategoryModelList.length, itemBuilder: (ctx, index) => _buildSingleCategory(name: AppProvider.getCategoryModelList[index].name, image: AppProvider.getCategoryModelList[index].image, ), ), ), ], ), ); } }
either create an instance from AppProvider like this:要么像这样从 AppProvider 创建一个实例:
AppProvider appProvider = AppProvider();
appProvider.getCategoryModelList.length
or define ' getCategoryModelList
' as static List
或将“ getCategoryModelList
”定义为static List
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.