From 0a51afa1eb632d82a95796ee13e888eef19dc53b Mon Sep 17 00:00:00 2001 From: Mohammad Hamed <67291298+Hamsho@users.noreply.github.com> Date: Sun, 9 Jan 2022 12:36:41 +0200 Subject: [PATCH] round the price --- lib/home.dart | 2 +- lib/product_details.dart | 37 +++++++++++++++++++++---------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/lib/home.dart b/lib/home.dart index 87a63b4..88392ab 100644 --- a/lib/home.dart +++ b/lib/home.dart @@ -206,7 +206,7 @@ class _HomeState extends State { name: g['name'], imageBytes: res.bodyBytes, category: g['category'], - price: g['current_price'].toString(), + price: g['current_price'].roundToDouble().toString(), expiryDate: DateFormat('yyyy-MM-dd').format( DateTime.fromMillisecondsSinceEpoch(g['expiry_date'])), imagePath: "$baseUrl2/images/${g['image_id']}"); diff --git a/lib/product_details.dart b/lib/product_details.dart index 11bc14c..f581746 100644 --- a/lib/product_details.dart +++ b/lib/product_details.dart @@ -23,6 +23,7 @@ class ProductDetailsScreen extends StatefulWidget { _ProductDetailsScreenState createState() => _ProductDetailsScreenState(); } + class _ProductDetailsScreenState extends State { String? comment; @@ -136,7 +137,7 @@ class _ProductDetailsScreenState extends State { fontSize: 24, fontWeight: FontWeight.bold, ), - ) + ), ], ), const SizedBox( @@ -268,24 +269,26 @@ class _ProductDetailsScreenState extends State { var comments = jsonDecode(res.body); Product p = Product( - id: jsonData['id'], - imageId: jsonData['image_id'], - imageBytes: response.bodyBytes, - name: jsonData['name'], - category: jsonData['category'], - availableQuantity: jsonData['available_quantity'], - liked: jsonData['liked'], - expiryDate: jsonData['expiry_date'], - unitPrice: jsonData['unit_price'].toString(), - viewsCount: jsonData['views_count'].toString(), - likesCount: jsonData['likes_count'].toString(), - contactPhone: jsonData['contact_phone'], - currentPrice: jsonData['current_price'].toString(), - comments: comments); + id: jsonData['id'], + imageId: jsonData['image_id'], + imageBytes: response.bodyBytes, + name: jsonData['name'], + category: jsonData['category'], + availableQuantity: jsonData['available_quantity'], + liked: jsonData['liked'], + expiryDate: jsonData['expiry_date'], + unitPrice: jsonData['unit_price'].toString(), + viewsCount: jsonData['views_count'].toString(), + likesCount: jsonData['likes_count'].toString(), + contactPhone: jsonData['contact_phone'], + currentPrice: jsonData['current_price'].roundToDouble().toString(), + comments: comments + ); product = p; // print(product.imageString); + } catch (e) { print("caught error"); print(e); @@ -311,7 +314,7 @@ Future likeRequest(int id, bool isLike) async { print(e); return false; } -} + } Future commentRequest(int id, String body) async { try { @@ -465,3 +468,5 @@ class Product { required this.currentPrice, required this.comments}); } + +