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