ist code is there . some one help me for this issu . i can't solve this issu .this type of problem i face first time so i can't solve it .please someone help me
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);
},
),
);
second code is controller section code . some one help me for this issu . i can't solve this issu .this type of problem i face first time so i can't solve it .please someone help me.
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);
}
}
}
CodePudding user response:
You should extends from GetxController
in the controller.
So just change GetxService
to GetxController
in the controller.
Please check below sample :
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);
}
}
}