Skip to content

Commit

Permalink
Merge pull request #500 from lyskouski/NF-499
Browse files Browse the repository at this point in the history
[#499] [NF] Add Currency Exchange. Add exchange page
  • Loading branch information
lyskouski authored Oct 3, 2024
2 parents dc972c1 + 1e207bf commit 68cb90e
Show file tree
Hide file tree
Showing 25 changed files with 214 additions and 18 deletions.
4 changes: 2 additions & 2 deletions lib/_classes/structure/currency_app_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class CurrencyAppData extends AbstractAppData {
String get descriptionFormatted => DateTime.parse(super.description ?? '').yMEd();

@override
String get title => '${currencyFrom?.code} -> ${currency?.code}';
String get title => '${currencyFrom?.code ?? '?'} -> ${currency?.code ?? '?'}';

@override
String get uuid => '${currencyFrom?.code}-${currency?.code}';
String get uuid => '${currencyFrom?.code ?? '?'}-${currency?.code ?? '?'}';
}
1 change: 1 addition & 0 deletions lib/_classes/structure/navigation/app_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ abstract class AppRoute {
static const String budgetSearchRoute = '/app/finance/budget/search';
static const String budgetEditRoute = '/app/finance/budget/edit';
static const String currencyRoute = '/app/finance/currency';
static const String currencyAddRoute = '/app/finance/currency/add';
static const String goalRoute = '/app/finance/goal';
static const String goalAddRoute = '/app/finance/goal/add';
static const String goalViewRoute = '/app/finance/goal/view';
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_ar.arb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
"credit": "ائتمان",
"creditCard": "بطاقة ائتمان",
"currency": "عملة",
"currencyAddHeadline": "صرف العملات",
"currencyAddTooltip": "إضافة سعر صرف العملة",
"currencyDefault": "العملة الافتراضية",
"currencyDistribution": "التوزيع",
"currencyExchange": "صرف العملات: {from} -> {to}",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_az.arb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
"credit": "Credit",
"creditCard": "Kredit kartı",
"currency": "Currency",
"currencyAddHeadline": "Valyuta mübadiləsi",
"currencyAddTooltip": "Valyuta məzənnəsini əlavə edin",
"currencyDefault": "Defolt Valyuta",
"currencyDistribution": "Paylanma",
"currencyExchange": "Valyuta mübadiləsi: {from} -> {to}",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_be.arb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
"credit": "Крэдыт",
"creditCard": "Крэдытная картка",
"currency": "Валюта",
"currencyAddHeadline": "Абмен валюты",
"currencyAddTooltip": "Дадаць курс абмену валюты",
"currencyDefault": "Безумоўная валюта",
"currencyDistribution": "Размеркаваньне",
"currencyExchange": "Абмен валюты: {from} -> {to}",
Expand Down
4 changes: 3 additions & 1 deletion lib/l10n/app_be_EU.arb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"accountFrom": "Z Rachunku",
"accountHeadline": "Rachunki",
"accountTo": "Da Rachunka",
"accountTooltip": "Adkryć rachunki",
"accountTooltip": "Adkryć Rachunki",
"accountType": "Typ Rachunku",
"accountTypeTooltip": "Vybiarycie Typ Rachunku",
"acknowledgeTooltip": "Pryniać",
Expand Down Expand Up @@ -132,6 +132,8 @@
"credit": "Kredyt",
"creditCard": "Kredytnaja Kartka",
"currency": "Valiuta",
"currencyAddHeadline": "Abmien Valiuty",
"currencyAddTooltip": "Dadać kurs abmienu valiuty",
"currencyDefault": "Biezumoŭnaja Valiuta",
"currencyDistribution": "Razmierkavańnie",
"currencyExchange": "Abmien Valiuty: {from} -> {to}",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
"credit": "Kredit",
"creditCard": "Kreditkarte",
"currency": "Währung",
"currencyAddHeadline": "Währungsumtausch",
"currencyAddTooltip": "Devisenkurs hinzufügen",
"currencyDefault": "Standardwährung",
"currencyDistribution": "Vertrieb",
"currencyExchange": "Währungsumtausch: {from} -> {to}",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
"credit": "Credit",
"creditCard": "Credit Card",
"currency": "Currency",
"currencyAddHeadline": "Currency Exchange",
"currencyAddTooltip": "Add Currency Exchange Rate",
"currencyDefault": "Default Currency",
"currencyDistribution": "Distribution",
"currencyExchange": "Currency Exchange: {from} -> {to}",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
"credit": "Credit",
"creditCard": "Tarjeta de crédito",
"currency": "Moneda",
"currencyAddHeadline": "Cambio de divisas",
"currencyAddTooltip": "Añadir tipo de cambio",
"currencyDefault": "Moneda por defecto",
"currencyDistribution": "Distribución",
"currencyExchange": "Cambio de divisas: {from} -> {to}",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_fa.arb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
"credit": "اعتبار",
"creditCard": "کارت اعتباری",
"currency": "واحد پول",
"currencyAddHeadline": "مبادله ارز",
"currencyAddTooltip": "اضافه کردن نرخ تبدیل ارز",
"currencyDefault": "ارز پیش فرض",
"currencyDistribution": "توزیع",
"currencyExchange": "مبادله ارز: {from} -> {to}",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
"credit": "Crédit",
"creditCard": "Carte de crédit",
"currency": "Devise",
"currencyAddHeadline": "Change de devises",
"currencyAddTooltip": "Ajouter le taux de change",
"currencyDefault": "Devise par défaut",
"currencyDistribution": "Distribution",
"currencyExchange": "Échange de devises : {from} -> {to}",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_hi.arb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
"credit": "श्रेय",
"creditCard": "क्रेडिट कार्ड",
"currency": "मुद्रा",
"currencyAddHeadline": "मुद्रा विनिमय",
"currencyAddTooltip": "मुद्रा विनिमय दर जोड़ें",
"currencyDefault": "डिफ़ॉल्ट मुद्रा",
"currencyDistribution": "वितरण",
"currencyExchange": "मुद्रा विनिमय: {from} -> {to}",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_it.arb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
"credit": "Credito",
"creditCard": "Carta di credito",
"currency": "Valuta",
"currencyAddHeadline": "Cambio valuta",
"currencyAddTooltip": "Aggiungere il tasso di cambio della valuta",
"currencyDefault": "Valuta predefinita",
"currencyDistribution": "Distribuzione",
"currencyExchange": "Scambio di valuta: {from} -> {to}",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_ja.arb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
"credit": "クレジット",
"creditCard": "クレジットカード",
"currency": "通貨",
"currencyAddHeadline": "両替",
"currencyAddTooltip": "為替レートを追加する",
"currencyDefault": "デフォルト通貨",
"currencyDistribution": "配布",
"currencyExchange": "通貨交換: {from} → {to}",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_pl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
"credit": "Kredyt",
"creditCard": "Karta kredytowa",
"currency": "Waluta",
"currencyAddHeadline": "Wymiana walut",
"currencyAddTooltip": "Dodaj kurs wymiany walut",
"currencyDefault": "Domyślna waluta",
"currencyDistribution": "Dystrybucja",
"currencyExchange": "Wymiana walut: {from} -> {to}",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_pt.arb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
"credit": "Crédito",
"creditCard": "Cartão de crédito",
"currency": "Moeda",
"currencyAddHeadline": "Câmbio de moeda",
"currencyAddTooltip": "Adicionar taxa de câmbio",
"currencyDefault": "Moeda predefinida",
"currencyDistribution": "Distribuição",
"currencyExchange": "Câmbio de moeda: {from} -> {to}",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_pt_BR.arb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
"credit": "Crédito",
"creditCard": "Cartão de crédito",
"currency": "Moeda",
"currencyAddHeadline": "Câmbio de moedas",
"currencyAddTooltip": "Adicionar taxa de câmbio",
"currencyDefault": "Moeda padrão",
"currencyDistribution": "Distribuição",
"currencyExchange": "Câmbio de moedas: {from} -> {to}",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_tr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
"credit": "Kredi",
"creditCard": "Kredi Kartı",
"currency": "Para Birimi",
"currencyAddHeadline": "Döviz Bozdurma",
"currencyAddTooltip": "Döviz Kuru Ekle",
"currencyDefault": "Varsayılan Para Birimi",
"currencyDistribution": "Dağıtım",
"currencyExchange": "Para Birimi Değişimi: {from} -> {to}",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_uk.arb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
"credit": "Кредит",
"creditCard": "Кредитна картка",
"currency": "Валюта",
"currencyAddHeadline": "Обмін валют",
"currencyAddTooltip": "Додати курс обміну валюти",
"currencyDefault": "Безумовна валюта",
"currencyDistribution": "Розподіл",
"currencyExchange": "Обмін валюти: {from} -> {to}",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_uz.arb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
"credit": "Credit",
"creditCard": "Kredit kartasi",
"currency": "Valyuta",
"currencyAddHeadline": "Valyuta ayirboshlash",
"currencyAddTooltip": "Valyuta kursini qo'shing",
"currencyDefault": "Standart valyuta",
"currencyDistribution": "Tarqatish",
"currencyExchange": "Valyuta almashinuvi: {from} -> {to}",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
"credit": "信用",
"creditCard": "信用卡",
"currency": "货币",
"currencyAddHeadline": "货币兑换",
"currencyAddTooltip": "添加货币汇率",
"currencyDefault": "默认货币",
"currencyDistribution": "分配",
"currencyExchange": "货币兑换:{from} -> {to}",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_zh_TW.arb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
"credit": "信貸",
"creditCard": "信用卡",
"currency": "貨幣",
"currencyAddHeadline": "貨幣兌換",
"currencyAddTooltip": "加入貨幣匯率",
"currencyDefault": "預設貨幣",
"currencyDistribution": "分佈",
"currencyExchange": "貨幣兌換: {from} -> {to}",
Expand Down
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import 'package:app_finance/pages/budget/budget_page.dart';
import 'package:app_finance/pages/budget/budget_add_page.dart';
import 'package:app_finance/pages/budget/budget_edit_page.dart';
import 'package:app_finance/pages/budget/budget_view_page.dart';
import 'package:app_finance/pages/currency/currency_add_page.dart';
import 'package:app_finance/pages/currency/currency_page.dart';
import 'package:app_finance/pages/goal/goal_add_page.dart';
import 'package:app_finance/pages/goal/goal_edit_page.dart';
Expand Down Expand Up @@ -162,6 +163,7 @@ class MyAppState extends State<MyApp> {
AppRoute.budgetSearchRoute => BudgetPage(search: key),
AppRoute.budgetEditRoute => BudgetEditPage(uuid: key),
AppRoute.currencyRoute => const CurrencyPage(),
AppRoute.currencyAddRoute => const CurrencyAddPage(),
AppRoute.goalRoute => const GoalPage(),
AppRoute.goalAddRoute => const GoalAddPage(),
AppRoute.goalViewRoute => GoalViewPage(uuid: key),
Expand Down
134 changes: 134 additions & 0 deletions lib/pages/currency/currency_add_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// Copyright 2024 The terCAD team. All rights reserved.
// Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.

import 'package:app_finance/_classes/controller/focus_controller.dart';
import 'package:app_finance/_classes/herald/app_design.dart';
import 'package:app_finance/_classes/herald/app_locale.dart';
import 'package:app_finance/_classes/structure/currency_app_data.dart';
import 'package:app_finance/_configs/theme_helper.dart';
import 'package:app_finance/design/form/simple_input.dart';
import 'package:app_finance/design/wrapper/input_wrapper.dart';
import 'package:app_finance/design/wrapper/single_scroll_wrapper.dart';
import 'package:app_finance/pages/_interfaces/abstract_add_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter_currency_picker/flutter_currency_picker.dart';

class CurrencyAddPage extends AbstractAddPage {
const CurrencyAddPage({super.key});

@override
CurrencyAddPageState createState() => CurrencyAddPageState();
}

class CurrencyAddPageState extends AbstractAddPageState<CurrencyAddPage> {
late FocusController focus;
Currency? currencyFrom;
Currency? currencyTo;
late TextEditingController conversion;

@override
void initState() {
focus = FocusController();
conversion = TextEditingController(text: '');
super.initState();
}

@override
void dispose() {
focus.dispose();
conversion.dispose();
super.dispose();
}

@override
String getTitle() => AppLocale.labels.currencyAddHeadline;

@override
String getButtonName() => AppLocale.labels.currencyAddTooltip;

@override
bool hasFormErrors() {
setState(() => hasError = currencyFrom == null ||
currencyTo == null ||
currencyFrom == currencyTo ||
conversion.text.isEmpty ||
double.tryParse(conversion.text) == 1.0);
return hasError;
}

@override
void updateStorage() {
final exchange = CurrencyAppData(
currency: currencyTo,
currencyFrom: currencyFrom,
details: double.tryParse(conversion.text) ?? 1.0,
);
state.update(exchange.uuid, exchange, true);
}

@override
void triggerActionButton(NavigatorState nav) {
setState(() {
if (hasFormErrors()) {
return;
}
updateStorage();
nav.pop();
});
}

@override
Widget buildButton(BuildContext context, BoxConstraints constraints) {
NavigatorState nav = Navigator.of(context);
return FloatingActionButton(
heroTag: 'currency_page_add',
onPressed: () => triggerActionButton(nav),
tooltip: getButtonName(),
child: const Icon(Icons.save),
);
}

@override
Widget buildContent(BuildContext context, BoxConstraints constraints) {
final indent = ThemeHelper.getIndent();
return SingleScrollWrapper(
controller: focus,
child: Padding(
padding: EdgeInsets.all(indent),
child: Column(
crossAxisAlignment: AppDesign.getAlignment(),
children: [
InputWrapper.currency(
isRequired: true,
showError: hasError && currencyFrom == null,
value: currencyFrom,
title: '${AppLocale.labels.currency} (${AppLocale.labels.from})',
tooltip: AppLocale.labels.currencyTooltip,
onChange: (value) => setState(() => currencyFrom = value),
),
InputWrapper.currency(
isRequired: true,
showError: hasError && (currencyTo == null || currencyFrom == currencyTo),
value: currencyTo,
title: '${AppLocale.labels.currency} (${AppLocale.labels.to})',
tooltip: AppLocale.labels.currencyTooltip,
onChange: (value) => setState(() => currencyTo = value),
),
InputWrapper.text(
title: AppLocale.labels.currencyExchange(currencyFrom?.code ?? '?', currencyTo?.code ?? '?'),
tooltip: AppLocale.labels.conversion,
isRequired: true,
showError: hasError && (conversion.text.isEmpty || double.tryParse(conversion.text) == 1.0),
controller: conversion,
inputType: const TextInputType.numberWithOptions(decimal: true),
formatter: [
SimpleInputFormatter.filterDouble,
],
),
ThemeHelper.formEndBox,
],
),
),
);
}
}
Loading

0 comments on commit 68cb90e

Please sign in to comment.