Update popular product with dynamic data
This commit is contained in:
parent
12bebabd96
commit
0d68c038e6
1 changed files with 50 additions and 18 deletions
|
@ -1,6 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:nekoya_flutter/screens/productcoba.dart';
|
||||
|
||||
import 'package:nekoya_flutter/api/api.dart';
|
||||
import '../utils/utils.dart';
|
||||
import 'product_card.dart';
|
||||
import 'section_title.dart';
|
||||
|
@ -21,25 +22,56 @@ class PopularProducts extends StatelessWidget {
|
|||
pressSeeAll: () {},
|
||||
),
|
||||
),
|
||||
SingleChildScrollView(
|
||||
physics: const BouncingScrollPhysics(
|
||||
parent: AlwaysScrollableScrollPhysics()),
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: List.generate(
|
||||
demoProduct.length,
|
||||
(index) => Padding(
|
||||
padding: const EdgeInsets.only(right: defaultPadding),
|
||||
child: ProductCard(
|
||||
title: demoProduct[index].title,
|
||||
image: demoProduct[index].image,
|
||||
price: demoProduct[index].price,
|
||||
bgColor: demoProduct[index].bgColor,
|
||||
press: () {},
|
||||
FutureBuilder<dynamic>(
|
||||
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']}",
|
||||
price: 99,
|
||||
bgColor: const Color(0xFFFEFBF9),
|
||||
press: () {},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
} 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",
|
||||
price: 99,
|
||||
bgColor: const Color(0xFFFEFBF9),
|
||||
press: () {},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
)
|
||||
],
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue