'Flutter listview.builder doesn't show more than 10 products but I have 100 products
class IlacProductRepo extends GetxService {
final ApiClient apiClient;
IlacProductRepo({required this.apiClient});
Future<Response> getIlacProductList() async {
return await apiClient.getData(AppConstans.ALL_PRODUCT_ILAC);
}
}
class IlacProductController extends GetxController {
final IlacProductRepo ilacProductRepo;
IlacProductController({required this.ilacProductRepo});
List<dynamic> _ilacproductList = [];
List<dynamic> get ilacproductList => _ilacproductList;
bool _isLoaded = false;
bool get isLoaded => _isLoaded ;
Future<void> getIlacProductList() async {
Response response = await ilacProductRepo.getIlacProductList();
if (response.statusCode == 200) {
print("got ilaç");
_ilacproductList = [];
_ilacproductList.addAll(Product.fromJson(response.body).products);
_isLoaded=true;
update();
} else {return print("something wrong");}
}
}
//another page
case Page.ilac:
return GetBuilder<IlacProductController>(builder: (ilacProduct) {
return ilacProduct.isLoaded
? ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: ilacProduct.ilacproductList.length,
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
Get.toNamed(RouteHelper.getIlacProduct(index));
},
child: Container(
margin: EdgeInsets.only(
left: Dimensions.width20,
right: Dimensions.width10,
bottom: Dimensions.height15),
child: Row(
children: [
//image section
Container(
width: Dimensions.listViewImgSize,
height: Dimensions.listViewImgSize,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(
Dimensions.radius20),
color: Colors.white38,
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
AppConstans.BASE_URL +
AppConstans.UPLOAD_URL +
ilacProduct
.ilacproductList[index]
.img!))),
),
//text section
Expanded(
child: Container(
height: Dimensions.listViewTextContSize,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(
Dimensions.radius20),
bottomRight: Radius.circular(
Dimensions.radius20)),
color: Colors.white),
child: Padding(
padding: EdgeInsets.only(
left: Dimensions.width10,
right: Dimensions.width10),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
mainAxisAlignment:
MainAxisAlignment.center,
children: [
BigText(
text: ilacProduct
.ilacproductList[index].name!,
),
SizedBox(
height: Dimensions.height10,
),
ExpandableProductText(text: ilacProduct
.ilacproductList[index].description!),
SizedBox(
height: Dimensions.height10,
),
],
),
),
),
)
],
)),
);
})
: const CircularProgressIndicator(
color: AppColor.mainColor,
);
});
break;
As I mentioned in the title, I will have close to 1000 products, but at the moment, there are no more than 10 in the application.
I don't know what the problem is, I think it can't be item count, I wonder if I made a logic error in the controller part?
As I mentioned in the title, I will have close to 1000 products, but at the moment, there are no more than 10 in the application.
I don't know what the problem is, I think it can't be item count, I wonder if I made a logic error in the controller part?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
