如何修复flutter依赖项中的错误“_buildCategoryList”需要2个位置参数,但找到1个,”?

frebpwbc  于 2023-05-23  发布在  Flutter
关注(0)|答案(1)|浏览(253)

“_buildCategoryList”需要2个位置参数,但找到了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>());
        },
        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,
              });
            },
hmae6n7t

hmae6n7t1#

由于_buildCategoryList小部件有两个参数,但您只传递了一个参数。

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(),
    ),
  );
}

相关问题