From b3bf8096501481fd880cb9a5e915c563a0427a8c Mon Sep 17 00:00:00 2001 From: Moe Poi ~ Date: Fri, 10 Nov 2023 12:43:01 +0700 Subject: [PATCH] Add discount price to product detail --- lib/components/product_box.dart | 2 +- lib/components/product_detail.dart | 43 +++++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/lib/components/product_box.dart b/lib/components/product_box.dart index b3022e6..7b6b5ca 100644 --- a/lib/components/product_box.dart +++ b/lib/components/product_box.dart @@ -92,7 +92,7 @@ class _ProductBoxState extends State { bottomLeft: Radius.circular(10.0))), margin: const EdgeInsets.only(top: 10.0), child: Center( - child: Text("${widget.discount}%", + child: Text("${widget.discount}% off", style: const TextStyle( color: Colors.white)))), ], diff --git a/lib/components/product_detail.dart b/lib/components/product_detail.dart index a927d1c..768278c 100644 --- a/lib/components/product_detail.dart +++ b/lib/components/product_detail.dart @@ -31,6 +31,11 @@ Widget productDetail(context, id) { builder: (context, snapshot) { if (snapshot.hasData) { var data = snapshot.data; + var discount = data[0]['DISCOUNT']; + if (discount != 0) { + discount = (100 - discount) / 100 * data[0]['PRICE']; + } + return Container( decoration: const BoxDecoration( color: Color(0xff1b1c1e), @@ -97,13 +102,37 @@ Widget productDetail(context, id) { ), ), DataCell( - Text( - "Rp ${NumberFormat('#,##0.00', 'ID').format(data[0]['PRICE'])}", - style: const TextStyle( - color: Colors.white, - fontSize: 18.0, - fontWeight: FontWeight.w500), - ), + discount != 0 + ? Column( + children: [ + Text( + "Rp ${NumberFormat('#,##0.00', 'ID').format(discount)}", + style: const TextStyle( + color: Colors.white, + fontSize: 18.0, + fontWeight: + FontWeight.w500), + ), + Text( + "Rp ${NumberFormat('#,##0.00', 'ID').format(data[0]['PRICE'])}", + style: const TextStyle( + color: Colors.white, + fontSize: 12.0, + fontWeight: FontWeight.w100, + decoration: TextDecoration + .lineThrough, + decorationColor: Colors.red, + decorationThickness: 3), + ) + ], + ) + : Text( + "Rp ${NumberFormat('#,##0.00', 'ID').format(data[0]['PRICE'])}", + style: const TextStyle( + color: Colors.white, + fontSize: 18.0, + fontWeight: FontWeight.w500), + ), ) ]), DataRow(cells: [