Make currenciychange work
parent
7c39c982de
commit
4e217d210c
|
@ -6,6 +6,7 @@ import 'package:shared_preferences/shared_preferences.dart';
|
|||
import 'package:tests/saving_tips.dart';
|
||||
import 'package:tests/transaction/transaction_dialog.dart';
|
||||
import 'package:tests/transaction/transaction.dart';
|
||||
import '../main.dart';
|
||||
import 'account.dart';
|
||||
import '../chart/expense_chart.dart';
|
||||
import '../chart/expense_data.dart';
|
||||
|
@ -29,11 +30,32 @@ class AccountDetailPageState extends State<AccountDetailPage>
|
|||
List<Transaction> incomeTransactions = [];
|
||||
List<Transaction> expenseTransactions = [];
|
||||
List<ExpenseData> expenseData = [];
|
||||
String _selectedCurrency="€";
|
||||
|
||||
Future<String> getCurrencyFromSharedPreferences(String key) async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
if (prefs.getString(key)=="Euro"){
|
||||
_selectedCurrency="€";
|
||||
}
|
||||
if (prefs.getString(key)=="Dollar"){
|
||||
_selectedCurrency=r"$";
|
||||
}
|
||||
if (prefs.getString(key)=="CHF"){
|
||||
_selectedCurrency="CHF";
|
||||
}
|
||||
|
||||
return prefs.getString(key) ?? 'Euro';
|
||||
}
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabController = TabController(length: 3, vsync: this);
|
||||
|
||||
getCurrencyFromSharedPreferences("currency").then((value) {
|
||||
setState(() {
|
||||
|
||||
});
|
||||
});
|
||||
loadTransactions();
|
||||
}
|
||||
|
||||
|
@ -167,7 +189,11 @@ class AccountDetailPageState extends State<AccountDetailPage>
|
|||
padding: const EdgeInsets.only(left: 16.0),
|
||||
child: NeumorphicButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(context); // Zurück zur vorherigen Seite
|
||||
Navigator.pushReplacement( // Neue Seite öffnen und vorherige Seite ersetzen
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => const HomePage()),
|
||||
);
|
||||
},
|
||||
style: NeumorphicStyle(
|
||||
shape: NeumorphicShape.flat,
|
||||
|
@ -329,7 +355,7 @@ class AccountDetailPageState extends State<AccountDetailPage>
|
|||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
'${value.round()}' '€',
|
||||
'${value.round()}$_selectedCurrency',
|
||||
),
|
||||
Text(
|
||||
'progress'.tr(),
|
||||
|
@ -349,8 +375,8 @@ class AccountDetailPageState extends State<AccountDetailPage>
|
|||
subtitle: Text(transactionsList[index].title),
|
||||
trailing: Text(
|
||||
transactionsList[index].isExpense
|
||||
? '-\$${transactionsList[index].amount.toStringAsFixed(2)}'
|
||||
: '+\$${transactionsList[index].amount.toStringAsFixed(2)}',
|
||||
? '-$_selectedCurrency${transactionsList[index].amount.toStringAsFixed(2)}'
|
||||
: '+$_selectedCurrency${transactionsList[index].amount.toStringAsFixed(2)}',
|
||||
style: TextStyle(
|
||||
color:
|
||||
transactionsList[index].isExpense ? Colors.red : Colors.green,
|
||||
|
|
|
@ -23,5 +23,6 @@
|
|||
"currency": "Währung",
|
||||
"budget": "Budgetcheck",
|
||||
"progress": "von deinem Budget ausgegeben",
|
||||
"monthlyexpenses": "Monatliche Ausgaben"
|
||||
"monthlyexpenses": "Monatliche Ausgaben",
|
||||
"close": "Schließen"
|
||||
}
|
|
@ -23,5 +23,6 @@
|
|||
"currency": "Currency",
|
||||
"budget": "Budget check",
|
||||
"progress": "of your budget spent",
|
||||
"monthlyexpenses": "Monthly Expenses"
|
||||
"monthlyexpenses": "Monthly Expenses",
|
||||
"close": "Close"
|
||||
}
|
|
@ -55,11 +55,32 @@ class HomePage extends StatefulWidget {
|
|||
|
||||
class HomePageState extends State<HomePage> {
|
||||
List<Account> accounts = [];
|
||||
String _selectedCurrency="€";
|
||||
|
||||
Future<String> getCurrencyFromSharedPreferences(String key) async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
if (prefs.getString(key)=="Euro"){
|
||||
_selectedCurrency="€";
|
||||
}
|
||||
if (prefs.getString(key)=="Dollar"){
|
||||
_selectedCurrency=r"$";
|
||||
}
|
||||
if (prefs.getString(key)=="CHF"){
|
||||
_selectedCurrency="CHF";
|
||||
}
|
||||
|
||||
return prefs.getString(key) ?? 'Euro';
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_themeManager.addListener(themeListener);
|
||||
getCurrencyFromSharedPreferences("currency").then((value) {
|
||||
setState(() {
|
||||
|
||||
});
|
||||
});
|
||||
loadAccounts();
|
||||
}
|
||||
|
||||
|
@ -187,7 +208,7 @@ class HomePageState extends State<HomePage> {
|
|||
child: ListTile(
|
||||
title: Text(accounts[index].name),
|
||||
subtitle: Text(
|
||||
'${'balance'.tr()}: \$${accounts[index].balance.toStringAsFixed(2)}'),
|
||||
'${'balance'.tr()}: $_selectedCurrency${accounts[index].balance.toStringAsFixed(2)}'),
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_neumorphic/flutter_neumorphic.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:tests/theme/theme_manager.dart';
|
||||
|
||||
import 'main.dart';
|
||||
|
||||
ThemeManager _themeManager = ThemeManager();
|
||||
|
||||
class Settings extends StatefulWidget {
|
||||
|
@ -40,6 +45,16 @@ class SettingsState extends State<Settings> {
|
|||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> saveCurrencyToSharedPreferences(String key, String value) async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString(key, value);
|
||||
}
|
||||
|
||||
Future<String> getCurrencyFromSharedPreferences(String key) async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
return prefs.getString(key) ?? 'Euro';
|
||||
}
|
||||
|
||||
themeListener() {
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
|
@ -50,6 +65,11 @@ class SettingsState extends State<Settings> {
|
|||
void initState() {
|
||||
super.initState();
|
||||
|
||||
getCurrencyFromSharedPreferences("currency").then((value) {
|
||||
setState(() {
|
||||
_selectedCurrency = value;
|
||||
});
|
||||
});
|
||||
_themeManager.addListener(themeListener);
|
||||
}
|
||||
|
||||
|
@ -82,7 +102,11 @@ class SettingsState extends State<Settings> {
|
|||
padding: const EdgeInsets.only(left: 16.0),
|
||||
child: NeumorphicButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context, "Change");
|
||||
Navigator.pop(context); // Zurück zur vorherigen Seite
|
||||
Navigator.pushReplacement( // Neue Seite öffnen und vorherige Seite ersetzen
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => const HomePage()),
|
||||
);
|
||||
},
|
||||
style: NeumorphicStyle(
|
||||
shape: NeumorphicShape.flat,
|
||||
|
@ -120,16 +144,10 @@ class SettingsState extends State<Settings> {
|
|||
lightSource: LightSource.topLeft,
|
||||
thumbShape: NeumorphicShape.concave,
|
||||
trackDepth: 5,
|
||||
// Weitere Style-Eigenschaften hier anpassen
|
||||
// Um den Switch heller zu machen, kannst du die Farben anpassen
|
||||
activeTrackColor: Colors.lightGreen,
|
||||
// Farbe für den aktiven Track
|
||||
inactiveTrackColor: Colors.grey.shade300,
|
||||
// Farbe für den inaktiven Track
|
||||
activeThumbColor: Colors.grey.shade100,
|
||||
// Farbe für den aktiven Thumb
|
||||
inactiveThumbColor:
|
||||
Colors.grey.shade200, // Farbe für den inaktiven Thumb
|
||||
inactiveThumbColor: Colors.grey.shade200,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -185,12 +203,10 @@ class SettingsState extends State<Settings> {
|
|||
onChanged: (String? newValue) {
|
||||
setState(() {
|
||||
_selectedCurrency = newValue!;
|
||||
// Hier kannst du die Währungseinstellung entsprechend anpassen
|
||||
// z.B. mit einer Funktion, die die Währung ändert.
|
||||
saveCurrencyToSharedPreferences("currency", _selectedCurrency);
|
||||
});
|
||||
},
|
||||
items:
|
||||
_currencies.map<DropdownMenuItem<String>>((String value) {
|
||||
items: _currencies.map<DropdownMenuItem<String>>((String value) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: value,
|
||||
child: Text(value),
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:carousel_slider/carousel_slider.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter_neumorphic/flutter_neumorphic.dart';
|
||||
|
||||
class SavingsTipsDialog extends StatelessWidget {
|
||||
|
@ -89,7 +90,7 @@ class SavingsTipsDialog extends StatelessWidget {
|
|||
boxShape:
|
||||
NeumorphicBoxShape.roundRect(BorderRadius.circular(15.0)),
|
||||
),
|
||||
child: const Text('Close'),
|
||||
child: Text('close'.tr()),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
Loading…
Reference in New Issue