Add: Getting items by its ids
This commit is contained in:
@@ -61,12 +61,15 @@ class _OrderConfirmationPageState extends State<OrderConfirmationPage> {
|
||||
List<GymItem> cartItems = [];
|
||||
double totalPrice = 0;
|
||||
List<GymItem> gymCart = [];
|
||||
bool _isLoading = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
Future.microtask(() => getCart().then((value) async {
|
||||
final items = await getItems(context);
|
||||
final itemIds =
|
||||
value.map((element) => element['id'] as String).toList();
|
||||
final items = await getItemsByIds(context, itemIds);
|
||||
setState(() {
|
||||
gymCart = items;
|
||||
cartItems = value.map((element) {
|
||||
@@ -76,6 +79,7 @@ class _OrderConfirmationPageState extends State<OrderConfirmationPage> {
|
||||
}).toList();
|
||||
totalPrice = cartItems.fold(
|
||||
0, (sum, item) => sum + item.price * item.localCount);
|
||||
_isLoading = false;
|
||||
});
|
||||
}));
|
||||
}
|
||||
@@ -98,24 +102,26 @@ class _OrderConfirmationPageState extends State<OrderConfirmationPage> {
|
||||
const GymLinkHeader(title: 'Оформление заказа'),
|
||||
const MarkdownBody(data: '## Состав заказа:'),
|
||||
Expanded(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxHeight: 350),
|
||||
child: ListView.builder(
|
||||
itemCount: cartItems.length,
|
||||
itemBuilder: (context, index) {
|
||||
final item = cartItems[index];
|
||||
return OrderConfirmItemCard(
|
||||
name: item.title,
|
||||
image: Image(
|
||||
image: NetworkImage(item.images[0].url),
|
||||
width: 50,
|
||||
height: 50),
|
||||
price: item.price,
|
||||
count: item.localCount,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
child: _isLoading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxHeight: 350),
|
||||
child: ListView.builder(
|
||||
itemCount: cartItems.length,
|
||||
itemBuilder: (context, index) {
|
||||
final item = cartItems[index];
|
||||
return OrderConfirmItemCard(
|
||||
name: item.title,
|
||||
image: Image(
|
||||
image: NetworkImage(item.images[0].url),
|
||||
width: 50,
|
||||
height: 50),
|
||||
price: item.price,
|
||||
count: item.localCount,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
|
||||
Reference in New Issue
Block a user