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.
76 lines
1.9 KiB
76 lines
1.9 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;
|
||
|
|
||
|
const NewArrivals({Key key, this.products}) : super(key: key);
|
||
|
@override
|
||
|
_NewArrivalsState createState() => _NewArrivalsState();
|
||
|
}
|
||
|
|
||
|
class _NewArrivalsState extends State<NewArrivals> {
|
||
|
ScrollController _controller;
|
||
|
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)
|
||
|
setState(() {
|
||
|
show.add(widget.products.elementAt(count));
|
||
|
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: StaggeredGridView.count(
|
||
|
controller: _controller,
|
||
|
crossAxisCount: 2,
|
||
|
children: List.generate(show.length, (int index) {
|
||
|
return index % 2 == 0
|
||
|
? buildProducts(context, show.elementAt(index))
|
||
|
: buildProducts(context, show.elementAt(index));
|
||
|
}),
|
||
|
staggeredTiles: List.generate(
|
||
|
show.length,
|
||
|
(int index) {
|
||
|
return StaggeredTile.fit(1);
|
||
|
},
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|