简体   繁体   English

需要帮助! 如何使用 flutter 中的 static 访问无法访问此实例成员“getCategoryModelList”

[英]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.

相关问题 Flutter 无法使用 static 访问访问实例成员“结果” - Flutter Instance member ‘result’ can’t be accessed using static access Flutter Instance 成员无法使用静态访问进行访问 - Flutter Instance member can't be accessed using static access 无法使用静态访问访问 Flutter 实例成员“{0}” - Flutter Instance member ‘{0}’ can’t be accessed using static access Flutter:无法使用静态访问访问实例成员“signInWithGoogle”。 (static_access_to_instance_member at ) - Flutter: Instance member 'signInWithGoogle' can't be accessed using static access. (static_access_to_instance_member at ) Flutter :“无法使用静态访问访问实例成员“正在播放”。” - Flutter : "Instance member 'playing' can't be accessed using static access." Flutter 错误:无法使用 static 访问访问实例成员“用户” - Flutter Error: Instance member 'user' can't be accessed using static access Flutter/Dart - 无法使用 static 访问访问实例成员“displayNotification” - Flutter/Dart - Instance member 'displayNotification' can't be accessed using static access Flutter 错误:无法使用 static 访问实例成员“takePicture” - Flutter error: Instance member 'takePicture' can't be accessed using static access 无法使用静态访问访问实例成员“用户” - Instance member 'user' can't be accessed using static access 无法使用静态访问访问实例成员“updateUser” - Instance member 'updateUser' can't be accessed using static access
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM