'PopularProductController' 不符合类型参数 'T' 的绑定 'GetxController'

'PopularProductController' doesn't conform to the bound 'GetxController' of the type parameter 'T'

存在代码。有人帮我解决这个问题。我无法解决这个问题。这种类型的问题我第一次遇到所以我无法解决。请有人帮助我

  Widget build(BuildContext context) {
    print("current height is " + MediaQuery.of(context).size.height.toString());
    print("current width is " + MediaQuery.of(context).size.width.toString());
    return Column(
      children: [
        //slider section
        GetBuilder<PopularProductController>(builder:(popularproducts){
          return Container(
            // color: Colors.blue,
            height: Dimentions.pageView,
            child: PageView.builder(
              controller: pageController,
              itemCount: 5,
              itemBuilder: (context, position) {
                return _buildPageItem(position);
              },
            ),
          );

第二个代码是控制器部分代码。有人帮我解决这个问题。我无法解决这个问题。这种类型的问题我第一次遇到所以我无法解决。请有人帮助我。

import 'package:fooddeliver/data/repository/popular_product_repo.dart';
import 'package:fooddeliver/modals/products_modal.dart';
import 'package:get/get.dart';

class PopularProductController extends GetxService {
  final PopularProductRepo popularProductRepo;
  PopularProductController({required this.popularProductRepo});
  List<dynamic> _popularProductList = [];
  List<dynamic> get popularProductList => _popularProductList;
  Future<void> getPopularProductList() async {
    Response response = await popularProductRepo.getPopularProductlist();
    if (response.statusCode == 200) {
      _popularProductList = [];
      print('product list');

      _popularProductList.addAll(Product.fromJson(response.body).products);
      print(_popularProductList);
    }
  }
}

您应该在控制器中从 GetxController 扩展。

所以只需在控制器中将GetxService更改为GetxController即可。

请检查以下示例:

class PopularProductController extends GetxController {
  final PopularProductRepo popularProductRepo;
  PopularProductController({required this.popularProductRepo});
  List<dynamic> _popularProductList = [];
  List<dynamic> get popularProductList => _popularProductList;
  Future<void> getPopularProductList() async {
    Response response = await popularProductRepo.getPopularProductlist();
    if (response.statusCode == 200) {
      _popularProductList = [];
      print('product list');

      _popularProductList.addAll(Product.fromJson(response.body).products);
      print(_popularProductList);
    }
  }
}