英文:
How can I fix the error '2 positional arguments expected by '_buildCategoryList', but 1 found.' in flutter dependencies?
问题
Here is the translated code:
> 2个位置参数应该由'_buildCategoryList'期望,但只找到1个。
尝试添加缺少的参数
Widget _categoriesList(WidgetRef ref) {
final categories = ref.watch(
categoriesProvider(
PaginationModel(page: 1, pageSize: 10),
),
);
return categories.when(
data: (list) {
return _buildCategoryList(list!.cast<Category>(), ref);
},
error: (_, __) => const Center(
child: Text("ERR"),
),
loading: () => const Center(
child: CircularProgressIndicator(),
));
}
Widget _buildCategoryList(List<Category> categories, WidgetRef ref) {
return Container(
child: ListView.builder(
shrinkWrap: true,
physics: const ClampingScrollPhysics(),
scrollDirection: Axis.horizontal,
itemCount: categories.length,
itemBuilder: (context, index) {
var data = categories[index];
return GestureDetector(
onTap: () {
ProductFilterModel filterModel = ProductFilterModel(
paginationModel: PaginationModel(page: 1, pageSize: 10),
categoryId: data.categoryId);
ref
.read(productsFilterProvider.notifier)
.setProductFilter(filterModel);
ref.read(productsNotifierProvider.notifier).getProducts();
Navigator.of(context).pushNamed("/products", arguments: {
'categoryId': data.categoryId,
'categoryName': data.categoryName,
});
},
Please note that I added the missing argument ref
to the _buildCategoryList
function call as required.
英文:
> 2 positional arguments expected by '_buildCategoryList', but 1 found.
Try adding the missing arguments
Widget _categoriesList(WidgetRef ref) {
final categories = ref.watch(
categoriesProvider(
PaginationModel(page: 1, pageSize: 10),
),
);
return categories.when(
data: (list) {
return _buildCategoryList(list!.cast<Category>());
},
error: (_, __) => const Center(
child: Text("ERR"),
),
loading: () => const Center(
child: CircularProgressIndicator(),
));
}
Widget _buildCategoryList(List<Category> categories, WidgetRef ref) {
return Container(
child: ListView.builder(
shrinkWrap: true,
physics: const ClampingScrollPhysics(),
scrollDirection: Axis.horizontal,
itemCount: categories.length,
itemBuilder: (context, index) {
var data = categories[index];
return GestureDetector(
onTap: () {
ProductFilterModel filterModel = ProductFilterModel(
paginationModel: PaginationModel(page: 1, pageSize: 10),
categoryId: data.categoryId);
ref
.read(productsFilterProvider.notifier)
.setProductFilter(filterModel);
ref.read(productsNotifierProvider.notifier).getProducts();
Navigator.of(context).pushNamed("/products", arguments: {
'categoryId': data.categoryId,
'categoryName': data.categoryName,
});
},
答案1
得分: 0
Since your _buildCategoryList
widget has two arguments but you are
passing only one argument.
Widget _categoriesList(WidgetRef ref) {
final categories = ref.watch(
categoriesProvider(
PaginationModel(page: 1, pageSize: 10),
),
);
return categories.when(
data: (list) {
return _buildCategoryList(list!.cast<Category>(), ref); // Pass both arguments
},
error: (_, __) => const Center(
child: Text("ERR"),
),
loading: () => const Center(
child: CircularProgressIndicator(),
),
);
}
英文:
Since your _buildCategoryList
widget has two arguments but you are
passing only one argument.
Widget _categoriesList(WidgetRef ref) {
final categories = ref.watch(
categoriesProvider(
PaginationModel(page: 1, pageSize: 10),
),
);
return categories.when(
data: (list) {
return _buildCategoryList(list!.cast<Category>(), ref); // Pass both arguments
},
error: (_, __) => const Center(
child: Text("ERR"),
),
loading: () => const Center(
child: CircularProgressIndicator(),
),
);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论