Skip to content

Commit

Permalink
improve ui of static asset & use dollar sign in prefix (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
ozgunozerk authored Jan 1, 2024
1 parent 1d32d3d commit 657d25d
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 23 deletions.
11 changes: 6 additions & 5 deletions lib/controllers/helpers/currency.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ class CurrencyController extends GetxController {
}

String displayCurrencyWithoutSign(double value) {
return formatWithoutSign(value * getCurrencyConversionRate) +
getCurrencySymbol;
return getCurrencySymbol +
formatWithoutSign(value * getCurrencyConversionRate);
}

String displayCurrencyWithSign2Decimals(double value) {
return formatWithSign2Decimal(value * getCurrencyConversionRate) +
getCurrencySymbol;
String displayCurrencyWithSign(double value,
{bool displayPositiveSign = false}) {
return formatWithSign2Decimal(value * getCurrencyConversionRate,
displayPositiveSign: displayPositiveSign, symbol: getCurrencySymbol);
}
}
1 change: 0 additions & 1 deletion lib/presentation/pages/main/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:how_much/presentation/ui/colours.dart';
import 'package:how_much/util/helper_funcs.dart';
import 'package:ionicons/ionicons.dart';

import 'package:how_much/controllers/auth.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/ui/text_styles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const TextStyle assetTextStyle = TextStyle(

TextStyle changeTextStyle(double change) {
return TextStyle(
fontSize: 14,
fontSize: 13,
color: change.isNegative ? red : green,
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/widgets/cards/category_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class CategoryCard extends StatelessWidget {
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(controller.displayCurrencyWithSign2Decimals(profit),
Text(controller.displayCurrencyWithSign(profit),
style: categoryProfitDepositAmountTextStyle),
const Text("profit",
style: categoryProfitDepositDescriptorTextStyle)
Expand Down
3 changes: 2 additions & 1 deletion lib/presentation/widgets/cards/small_category_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class SmallCategoryCard extends StatelessWidget {
controller.displayCurrencyWithoutSign(totalAmount),
style: smallCategoryHeaderTextStyle)),
Obx(() => Text(
controller.displayCurrencyWithSign2Decimals(profit),
controller.displayCurrencyWithSign(profit,
displayPositiveSign: true),
style: smallCategoryChangeTextStyle(profit))),
],
),
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/widgets/cards/static_asset_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class StaticAssetCard extends StatelessWidget {
style: assetTextStyle,
)),
Obx(() => Text(
"${controller.displayCurrencyWithSign2Decimals(profit)} (${formatWithSign2Decimal(rateChange)}%)",
"${controller.displayCurrencyWithSign(profit, displayPositiveSign: true)} (${formatWithSign2Decimal(rateChange, displayPositiveSign: true)}%)",
style: changeTextStyle(profit),
)),
],
Expand Down
27 changes: 14 additions & 13 deletions lib/util/parsing.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import 'package:intl/intl.dart';

final numFormatter = NumberFormat("#,###.##", "en_US");

String formatWithSign2Decimal(double myDouble) {
if (myDouble == 0) {
return '0.00';
}
final numFormatter = NumberFormat("#,##0.00", "en_US");

String formatWithSign2Decimal(double myDouble,
{bool displayPositiveSign = false, String symbol = ''}) {
String formatted = numFormatter.format(myDouble);

// Add the leading zero if not present
// negative case
if (formatted.startsWith('-.')) {
formatted = formatted.replaceFirst('-.', '-0.');
// Add the positive sign if required
if (displayPositiveSign && !formatted.startsWith('-')) {
formatted = "+$formatted";
}
// positive case
if (formatted.startsWith('.')) {
formatted = formatted.replaceFirst('.', '0.');

// If symbol is given, add it before the first number
if (symbol != '') {
int insertIndex =
formatted.startsWith('-') ? 1 : (displayPositiveSign ? 1 : 0);
formatted = formatted.substring(0, insertIndex) +
symbol +
formatted.substring(insertIndex);
}

return formatted;
Expand Down

0 comments on commit 657d25d

Please sign in to comment.