You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.8 KiB

3 years ago
import 'package:teso/Classes/API%20Clasess/Product.dart';
import 'package:teso/Pages/PageWidgets/Explore/products.dart';
import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
class NewArrivals extends StatefulWidget {
final List<Product>? products;
3 years ago
const NewArrivals({Key? key, this.products}) : super(key: key);
3 years ago
@override
_NewArrivalsState createState() => _NewArrivalsState();
}
class _NewArrivalsState extends State<NewArrivals> {
late ScrollController _controller;
3 years ago
List<Product> show = [];
int count = 0;
Future<void> fetchImages() async {
try {
count = show.length;
for (int i = 0; i <= 9; i++) {
if (widget.products!.length > count)
3 years ago
setState(() {
show.add(widget.products!.elementAt(count));
3 years ago
count++;
imageCache.clear();
});
}
} catch (e) {
print(e);
}
}
void _scrollListener() {
if (_controller.offset >= _controller.position.maxScrollExtent &&
!_controller.position.outOfRange) {
fetchImages();
}
}
@override
void initState() {
_controller = ScrollController();
_controller.addListener(_scrollListener);
count = 0;
fetchImages();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: true,
title: Text("New Arrivals"),
),
body: StaggeredGrid.count(
3 years ago
crossAxisCount: 2,
children: List.generate(show.length, (int index) {
return index % 2 == 0
? buildProducts(context, show.elementAt(index))
: buildProducts(context, show.elementAt(index));
}),
3 years ago
),
);
}
}