2022-05-16 02:51:47 +02:00
|
|
|
import 'package:intl/intl.dart';
|
2022-04-28 08:56:12 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-05-16 02:51:47 +02:00
|
|
|
|
2022-04-28 09:20:01 +02:00
|
|
|
import 'package:nekoya_flutter/api/api.dart';
|
|
|
|
import 'package:nekoya_flutter/data/cart.dart';
|
|
|
|
import 'package:nekoya_flutter/components/cart_box.dart';
|
2022-04-28 08:56:12 +02:00
|
|
|
|
|
|
|
class CheckoutItems extends StatefulWidget {
|
2022-04-28 21:20:36 +02:00
|
|
|
const CheckoutItems({Key? key}) : super(key: key);
|
2022-04-28 08:56:12 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
State<CheckoutItems> createState() => _CheckoutItemsState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _CheckoutItemsState extends State<CheckoutItems> {
|
2022-04-29 17:57:32 +02:00
|
|
|
|
2022-04-28 08:56:12 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-04-29 17:57:32 +02:00
|
|
|
Future<dynamic> getTotal() async {
|
|
|
|
dynamic totalPrice = 0;
|
2022-04-30 04:44:45 +02:00
|
|
|
var orderData = await viewCart();
|
2022-04-29 17:57:32 +02:00
|
|
|
await orderData.forEach((x) async {
|
|
|
|
var product = await getProduct(x['product_id']);
|
|
|
|
totalPrice += product[0]['PRICE'] * x['quantity'];
|
|
|
|
});
|
|
|
|
|
2022-04-30 04:51:08 +02:00
|
|
|
return Future.delayed(const Duration(seconds: 2), () {
|
2022-04-29 17:57:32 +02:00
|
|
|
return totalPrice;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-28 09:20:01 +02:00
|
|
|
return Container(
|
|
|
|
margin: const EdgeInsets.fromLTRB(10, 10, 10, 5),
|
|
|
|
child: Card(
|
|
|
|
color: const Color(0xff212226),
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(15),
|
|
|
|
),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
const SizedBox(
|
|
|
|
height: 20,
|
|
|
|
),
|
|
|
|
const Center(
|
|
|
|
child: Text(
|
|
|
|
"Items in Cart",
|
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.white,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 30),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
FutureBuilder<dynamic>(
|
2022-04-28 21:20:36 +02:00
|
|
|
future: viewCart(),
|
2022-04-28 09:20:01 +02:00
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
var data = snapshot.data;
|
|
|
|
return ListView.builder(
|
|
|
|
scrollDirection: Axis.vertical,
|
|
|
|
shrinkWrap: true,
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
itemCount: data!.length,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
return FutureBuilder<dynamic>(
|
|
|
|
future: getProduct(data[index]["product_id"]),
|
|
|
|
builder: (context, snapshotx) {
|
|
|
|
if (snapshotx.hasData) {
|
|
|
|
var productData = snapshotx.data;
|
|
|
|
if (productData != null) {
|
|
|
|
return CartBox(
|
|
|
|
controller: false,
|
2022-05-12 05:27:53 +02:00
|
|
|
imageUrl: "https://nekoya.moe.team/img/${productData[0]['IMAGE']}",
|
2022-04-28 09:20:01 +02:00
|
|
|
title: productData[0]['TITLE'],
|
|
|
|
quantity: data[index]["quantity"],
|
|
|
|
plus: () {},
|
|
|
|
minus: () {},
|
|
|
|
remove: () {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return CartBox(
|
|
|
|
controller: false,
|
|
|
|
imageUrl:
|
|
|
|
'https://i.ibb.co/QJFLZC4/La-Darknesss-Portrait.webp',
|
|
|
|
title: 'Loading...',
|
|
|
|
quantity: 0,
|
|
|
|
plus: () {},
|
|
|
|
minus: () {},
|
|
|
|
remove: () {},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return const Center(
|
|
|
|
child: CircularProgressIndicator(
|
|
|
|
color: Color(0xff8B0000),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2022-04-29 17:57:32 +02:00
|
|
|
Container(
|
|
|
|
margin:
|
|
|
|
const EdgeInsets.only(top: 15.0, right: 15.0, bottom: 20.0),
|
|
|
|
child: FutureBuilder<dynamic>(
|
|
|
|
future: getTotal(),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
var price = snapshot.data;
|
|
|
|
return Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"Total : Rp ${NumberFormat('#,##0.00', 'ID').format(price)}",
|
|
|
|
style: const TextStyle(
|
|
|
|
color: Colors.white,
|
|
|
|
fontSize: 18,
|
|
|
|
fontWeight: FontWeight.w600),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
children: const [
|
|
|
|
Text(
|
|
|
|
"Total : -",
|
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.white,
|
|
|
|
fontSize: 18,
|
|
|
|
fontWeight: FontWeight.w600),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
2022-04-28 09:20:01 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2022-04-28 08:56:12 +02:00
|
|
|
}
|
|
|
|
}
|