Add: images slider
This commit is contained in:
@@ -95,14 +95,16 @@ class _MainPageState extends State<MainPage> {
|
||||
}
|
||||
|
||||
void _onLoad() async {
|
||||
setState(() {
|
||||
isLoading = true;
|
||||
});
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
setState(() {
|
||||
itemViewCount = min(filteredData.length, itemViewCount + 5);
|
||||
isLoading = false;
|
||||
});
|
||||
if (itemViewCount < filteredData.length) {
|
||||
setState(() {
|
||||
isLoading = true;
|
||||
});
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
setState(() {
|
||||
itemViewCount = min(filteredData.length, itemViewCount + 5);
|
||||
isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _onSearch() {
|
||||
@@ -201,72 +203,76 @@ class _MainPageState extends State<MainPage> {
|
||||
child: LazyLoadScrollView(
|
||||
onEndOfPage: _onLoad,
|
||||
isLoading: isLoading,
|
||||
child: ListView(
|
||||
children: [
|
||||
items.isEmpty
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: filteredData.isEmpty
|
||||
? const Center(child: Text('Ничего не найдено'))
|
||||
: GridView.builder(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
shrinkWrap: true,
|
||||
gridDelegate:
|
||||
SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: min(
|
||||
(MediaQuery.sizeOf(context).width ~/ 200)
|
||||
.toInt(),
|
||||
8),
|
||||
),
|
||||
itemCount: itemViewCount,
|
||||
itemBuilder: (context, index) {
|
||||
final product = filteredData[index];
|
||||
return ProductCard(
|
||||
imagePath: Image(
|
||||
image: Image.network(product.images[0].url)
|
||||
.image,
|
||||
width: 50,
|
||||
),
|
||||
name: product.title,
|
||||
price: product.price.toString(),
|
||||
onTap: () => Navigator.of(context).push(
|
||||
CustomPageRoute(
|
||||
builder: (context) => DetailPage(
|
||||
id: product.id,
|
||||
child: Scrollbar(
|
||||
child: ListView(
|
||||
children: [
|
||||
items.isEmpty
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: filteredData.isEmpty
|
||||
? const Center(child: Text('Ничего не найдено'))
|
||||
: GridView.builder(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
shrinkWrap: true,
|
||||
gridDelegate:
|
||||
SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: min(
|
||||
(MediaQuery.sizeOf(context).width ~/ 200)
|
||||
.toInt(),
|
||||
8),
|
||||
),
|
||||
itemCount: itemViewCount,
|
||||
itemBuilder: (context, index) {
|
||||
final product = filteredData[index];
|
||||
return ProductCard(
|
||||
imagePath: Image(
|
||||
image:
|
||||
Image.network(product.images[0].url)
|
||||
.image,
|
||||
width: 50,
|
||||
),
|
||||
name: product.title,
|
||||
price: product.price.toString(),
|
||||
onTap: () => Navigator.of(context).push(
|
||||
CustomPageRoute(
|
||||
builder: (context) => DetailPage(
|
||||
id: product.id,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
itemViewCount > 0
|
||||
? Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: Center(
|
||||
child: itemViewCount < filteredData.length
|
||||
? !isLoading
|
||||
? ElevatedButton(
|
||||
onPressed: _onLoad,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor:
|
||||
Theme.of(context).primaryColor,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(50)),
|
||||
);
|
||||
},
|
||||
),
|
||||
itemViewCount > 0
|
||||
? Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: Center(
|
||||
child: itemViewCount < filteredData.length
|
||||
? !isLoading
|
||||
? ElevatedButton(
|
||||
onPressed: _onLoad,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor:
|
||||
Theme.of(context).primaryColor,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(50)),
|
||||
),
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
child: const Text('Загрузить ещё'),
|
||||
)
|
||||
: const CircularProgressIndicator()
|
||||
: const Text(
|
||||
'Конец списка',
|
||||
style: TextStyle(
|
||||
fontSize: 10, color: Color(0x88000000)),
|
||||
),
|
||||
),
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
],
|
||||
child: const Text('Загрузить ещё'),
|
||||
)
|
||||
: const CircularProgressIndicator()
|
||||
: const Text(
|
||||
'Конец списка',
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
color: Color(0x88000000)),
|
||||
),
|
||||
),
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user