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.
80 lines
2.0 KiB
80 lines
2.0 KiB
import 'package:flutter/material.dart';
|
|
import 'package:teso/Classes/TesoShop.dart';
|
|
|
|
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
|
import 'package:teso/Pages/PageWidgets/Explore/business.dart';
|
|
|
|
class ExploreBusiness extends StatefulWidget {
|
|
final List<TesoShop> businesses;
|
|
|
|
const ExploreBusiness({Key key, this.businesses}) : super(key: key);
|
|
@override
|
|
_ExploreBusinessState createState() => _ExploreBusinessState();
|
|
}
|
|
|
|
class _ExploreBusinessState extends State<ExploreBusiness> {
|
|
ScrollController _controller;
|
|
List<TesoShop> show = [];
|
|
int count = 0;
|
|
|
|
Future<void> fetchImages() async {
|
|
try {
|
|
count = show.length;
|
|
for (int i = 0; i <= 9; i++) {
|
|
if (widget.businesses.length > count)
|
|
setState(() {
|
|
show.add(widget.businesses.elementAt(count));
|
|
count++;
|
|
imageCache.clear();
|
|
});
|
|
}
|
|
} catch (e) {
|
|
print(e);
|
|
}
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(covariant ExploreBusiness oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
if (oldWidget.businesses != widget.businesses ||
|
|
widget.businesses.length == 0) {
|
|
show = [];
|
|
fetchImages();
|
|
}
|
|
}
|
|
|
|
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 Container(
|
|
child: StaggeredGridView.count(
|
|
controller: _controller,
|
|
crossAxisCount: 2,
|
|
children: List.generate(show.length, (int index) {
|
|
return buildBusiness(context, show.elementAt(index));
|
|
}),
|
|
staggeredTiles: List.generate(
|
|
show.length,
|
|
(int index) {
|
|
return StaggeredTile.fit(1);
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|