update payment total price

This commit is contained in:
D Shrat 2022-05-15 15:14:07 +07:00
parent 362438f97b
commit b974f458bc

View file

@ -1,4 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:nekoya_flutter/api/api.dart';
import 'package:nekoya_flutter/data/cart.dart';
import 'package:intl/intl.dart';
import 'package:nekoya_flutter/components/menu.dart'; import 'package:nekoya_flutter/components/menu.dart';
@ -12,6 +15,19 @@ class PaymentBody extends StatefulWidget {
class _PaymentBodyState extends State<PaymentBody> { class _PaymentBodyState extends State<PaymentBody> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Future<dynamic> getTotal() async {
dynamic totalPrice = 0;
var orderData = await viewCart();
await orderData.forEach((x) async {
var product = await getProduct(x['product_id']);
totalPrice += product[0]['PRICE'] * x['quantity'];
});
return Future.delayed(const Duration(seconds: 2), () {
return totalPrice;
});
}
return Container( return Container(
decoration: const BoxDecoration(color: Colors.transparent), decoration: const BoxDecoration(color: Colors.transparent),
child: ListView( child: ListView(
@ -104,16 +120,41 @@ class _PaymentBodyState extends State<PaymentBody> {
), ),
Container( Container(
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(0), borderRadius: BorderRadius.circular(18),
color: const Color(0xff8B0000), color: const Color(0xff8B0000),
), ),
child: const Text( child: FutureBuilder<dynamic>(
'13000000', future: getTotal(),
style: TextStyle( builder: (context, snapshot) {
fontSize: 30, if (snapshot.hasData) {
var price = snapshot.data;
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Rp ${NumberFormat('#,##0.00', 'ID').format(price)}",
style: const TextStyle(
color: Colors.white, color: Colors.white,
), fontSize: 25,
textAlign: TextAlign.center, fontWeight: FontWeight.w600),
)
],
);
}
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Text(
"Count total price on process!",
style: TextStyle(
color: Colors.white,
fontSize: 25,
fontWeight: FontWeight.w600),
)
],
);
},
), ),
), ),
Container( Container(