Reputation: 1
The error i get after running my code
below is a sample of the code"
` @override Widget build(BuildContext context) { return Column( children: [ //slider section GetBuilder(builder: (popularProducts) { return Container( height: Dimentions.pageView, child: PageView.builder( controller: pageController, itemCount: popularProducts.popularProductList.length, itemBuilder: (context, position) { return _buildPageItem(position); }), ); }),
//dots
GetBuilder<PopularProductController>(builder: (popularProducts) {
return DotsIndicator(
dotsCount: popularProducts.popularProductList.length,
position: _currPageValue,
decorator: DotsDecorator(
size: const Size.square(9.0),
activeColor: AppColors.mainColor,
activeSize: const Size(18.0, 9.0),
activeShape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0)),
),
);
}),`
The controller file
`import 'package:food_app/data/repository/popular_product_repos.dart';
import 'package:food_app/models/product_model.dart';
import 'package:get/get.dart';
class PopularProductController extends GetxController {
final PopularProductRepository popularProductRepository;
PopularProductController({required this.popularProductRepository});
List<dynamic> _popularProductList = [];
List<dynamic> get popularProductList => _popularProductList;
Future<void> getPopularProductList() async {
Response response = await popularProductRepository.getPopularProductList();
if (response.statusCode == 200) {
print("Got products");
_popularProductList = [];
_popularProductList.addAll(Product.fromJson(response.body).products);
update();
} else {}
}
}`
Upvotes: 0
Views: 768
Reputation: 1
**Use this logic **
position:_currentIndex>images.length? _currentIndex=0: _currentIndex,
Upvotes: 0
Reputation: 1
This value must not be zero:
GetBuilder<PopularProductController>(builder: (popularProducts) {
print(popularProducts.popularProductList.length);
return DotsIndicator(
dotsCount: popularProducts.popularProductList.isNotEmpty
? popularProducts.popularProductList.length
: 2,
position: _currPageValue,
decorator: DotsDecorator(
activeColor: AppColors.mainColor,
size: const Size.square(9.0),
activeSize: const Size(18.0, 9.0),
activeShape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0)),
),
);
}),
Upvotes: 0