From 9feb9d1b4bb8d4a1b3aaec77e5c0babed0a2dc0a Mon Sep 17 00:00:00 2001 From: Vaibhav Surve Date: Sat, 9 Aug 2025 19:08:01 +0530 Subject: [PATCH] displayed comma seperated amount on expenses --- .../widgets/expense_main_components.dart | 6 ++--- lib/model/expense/expense_list_model.dart | 24 +++++++++++++------ lib/view/expense/expense_screen.dart | 3 ++- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/lib/helpers/widgets/expense_main_components.dart b/lib/helpers/widgets/expense_main_components.dart index 0744b48..b6d0720 100644 --- a/lib/helpers/widgets/expense_main_components.dart +++ b/lib/helpers/widgets/expense_main_components.dart @@ -274,8 +274,7 @@ class ExpenseList extends StatelessWidget { const SizedBox(height: 16), MyText.titleLarge("Delete Expense", fontWeight: 600, - color: - Theme.of(context).colorScheme.onBackground), + color: Theme.of(context).colorScheme.onBackground), const SizedBox(height: 12), MyText.bodySmall( "Are you sure you want to delete this draft expense?", @@ -392,8 +391,7 @@ class ExpenseList extends StatelessWidget { fontWeight: 600), Row( children: [ - MyText.bodyMedium( - '₹ ${expense.amount.toStringAsFixed(2)}', + MyText.bodyMedium('₹ ${expense.formattedAmount}', fontWeight: 600), if (expense.status.name.toLowerCase() == 'draft') ...[ const SizedBox(width: 8), diff --git a/lib/model/expense/expense_list_model.dart b/lib/model/expense/expense_list_model.dart index bdebfb4..b37f83b 100644 --- a/lib/model/expense/expense_list_model.dart +++ b/lib/model/expense/expense_list_model.dart @@ -1,4 +1,5 @@ import 'dart:convert'; +import 'package:intl/intl.dart'; /// Parse the entire response ExpenseResponse expenseResponseFromJson(String str) => @@ -112,8 +113,9 @@ class Filter { statusIds: List.from(json["statusIds"] ?? []), createdByIds: List.from(json["createdByIds"] ?? []), paidById: List.from(json["paidById"] ?? []), - startDate: - json["startDate"] != null ? DateTime.tryParse(json["startDate"]) : null, + startDate: json["startDate"] != null + ? DateTime.tryParse(json["startDate"]) + : null, endDate: json["endDate"] != null ? DateTime.tryParse(json["endDate"]) : null, ); @@ -162,6 +164,16 @@ class ExpenseModel { required this.preApproved, }); + /// ✅ Comma-separated amount getter with currency symbol + String get formattedAmount { + final formatter = NumberFormat.currency( + locale: 'en_IN', + symbol: '₹ ', + decimalDigits: 2, + ); + return formatter.format(amount); + } + factory ExpenseModel.fromJson(Map json) => ExpenseModel( id: json["id"] ?? '', project: Project.fromJson(json["project"] ?? {}), @@ -171,8 +183,7 @@ class ExpenseModel { createdBy: CreatedBy.fromJson(json["createdBy"] ?? {}), transactionDate: DateTime.tryParse(json["transactionDate"] ?? '') ?? DateTime.now(), - createdAt: - DateTime.tryParse(json["createdAt"] ?? '') ?? DateTime.now(), + createdAt: DateTime.tryParse(json["createdAt"] ?? '') ?? DateTime.now(), supplerName: json["supplerName"] ?? '', amount: (json["amount"] ?? 0).toDouble(), status: Status.fromJson(json["status"] ?? {}), @@ -226,8 +237,7 @@ class Project { shortName: json["shortName"] ?? '', projectAddress: json["projectAddress"] ?? '', contactPerson: json["contactPerson"] ?? '', - startDate: - DateTime.tryParse(json["startDate"] ?? '') ?? DateTime.now(), + startDate: DateTime.tryParse(json["startDate"] ?? '') ?? DateTime.now(), endDate: DateTime.tryParse(json["endDate"] ?? '') ?? DateTime.now(), projectStatusId: json["projectStatusId"] ?? '', ); @@ -390,7 +400,7 @@ class Status { name: json["name"] ?? '', displayName: json["displayName"] ?? '', description: json["description"] ?? '', - color: (json["color"] ?? '').replaceAll("'", ''), + color: (json["color"] ?? '').replaceAll("'", ''), isSystem: json["isSystem"] ?? false, ); diff --git a/lib/view/expense/expense_screen.dart b/lib/view/expense/expense_screen.dart index 4801f27..6ca157f 100644 --- a/lib/view/expense/expense_screen.dart +++ b/lib/view/expense/expense_screen.dart @@ -12,6 +12,7 @@ import 'package:marco/helpers/widgets/expense_main_components.dart'; import 'package:marco/helpers/utils/permission_constants.dart'; import 'package:marco/helpers/widgets/my_refresh_indicator.dart'; + class ExpenseMainScreen extends StatefulWidget { const ExpenseMainScreen({super.key}); @@ -105,7 +106,7 @@ class _ExpenseMainScreenState extends State { child: filteredList.isEmpty ? ListView( physics: - const AlwaysScrollableScrollPhysics(), // important + const AlwaysScrollableScrollPhysics(), children: [ SizedBox( height: MediaQuery.of(context).size.height * 0.5,