2022-05-13 06:02:53 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2022-05-15 16:45:16 +02:00
|
|
|
import 'package:nekoya_flutter/api/api.dart';
|
2022-05-16 02:51:47 +02:00
|
|
|
import 'package:nekoya_flutter/components/product_card.dart';
|
2022-05-15 17:08:30 +02:00
|
|
|
import 'package:nekoya_flutter/components/product_detail.dart';
|
2022-05-16 02:51:47 +02:00
|
|
|
import 'package:nekoya_flutter/components/section_title.dart';
|
|
|
|
import 'package:nekoya_flutter/utils/utils.dart';
|
2022-05-13 06:02:53 +02:00
|
|
|
|
|
|
|
class PopularProducts extends StatelessWidget {
|
|
|
|
const PopularProducts({
|
|
|
|
Key? key,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: defaultPadding),
|
|
|
|
child: SectionTitle(
|
2022-05-15 18:52:34 +02:00
|
|
|
title: "Best Seller",
|
2022-05-13 06:02:53 +02:00
|
|
|
pressSeeAll: () {},
|
|
|
|
),
|
|
|
|
),
|
2022-05-15 16:45:16 +02:00
|
|
|
FutureBuilder<dynamic>(
|
2022-05-15 18:52:34 +02:00
|
|
|
future: getProducts(),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
var sourceData = snapshot.data;
|
|
|
|
sourceData.shuffle();
|
|
|
|
var data = sourceData.take(6).toList();
|
|
|
|
return SingleChildScrollView(
|
|
|
|
physics: const BouncingScrollPhysics(
|
|
|
|
parent: AlwaysScrollableScrollPhysics()),
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
child: Row(
|
|
|
|
children: List.generate(
|
|
|
|
data.length,
|
|
|
|
(index) => Padding(
|
|
|
|
padding: const EdgeInsets.only(right: defaultPadding),
|
|
|
|
child: ProductCard(
|
|
|
|
title: data[index]['TITLE'],
|
|
|
|
imageUrl:
|
|
|
|
"https://nekoya.moe.team/img/${data[index]['IMAGE']}",
|
|
|
|
bgColor: const Color(0xFFFEFBF9),
|
|
|
|
press: () {
|
|
|
|
showModalBottomSheet(
|
|
|
|
isScrollControlled: true,
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
context: context,
|
|
|
|
builder: (context) =>
|
|
|
|
productDetail(context, data[index]['ID']),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2022-05-15 16:45:16 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-05-15 18:52:34 +02:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return SingleChildScrollView(
|
|
|
|
physics: const BouncingScrollPhysics(
|
|
|
|
parent: AlwaysScrollableScrollPhysics()),
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
child: Row(
|
|
|
|
children: List.generate(
|
|
|
|
6,
|
|
|
|
(index) => Padding(
|
|
|
|
padding: const EdgeInsets.only(right: defaultPadding),
|
|
|
|
child: ProductCard(
|
|
|
|
title: 'Loading...',
|
|
|
|
imageUrl:
|
|
|
|
"https://i.ibb.co/QJFLZC4/La-Darknesss-Portrait.webp",
|
|
|
|
bgColor: const Color(0xFFFEFBF9),
|
|
|
|
press: () {},
|
|
|
|
),
|
2022-05-15 16:45:16 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-05-15 18:52:34 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
})
|
2022-05-13 06:02:53 +02:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|