2023-06-12 20:53:03 +02:00
|
|
|
import 'dart:convert';
|
2023-06-14 00:26:04 +02:00
|
|
|
import 'package:awesome_dialog/awesome_dialog.dart';
|
2023-06-15 02:23:13 +02:00
|
|
|
import 'package:flutter/services.dart';
|
2023-06-14 00:26:04 +02:00
|
|
|
import 'package:flutter_neumorphic/flutter_neumorphic.dart';
|
2023-06-17 03:09:31 +02:00
|
|
|
import 'package:provider/provider.dart';
|
2023-06-12 20:53:03 +02:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2023-06-14 00:26:04 +02:00
|
|
|
import 'package:tests/preferences.dart';
|
|
|
|
import 'package:tests/theme/theme_constants.dart';
|
|
|
|
import 'package:tests/theme/theme_manager.dart';
|
2023-06-14 02:46:11 +02:00
|
|
|
import "package:easy_localization/easy_localization.dart";
|
2023-06-15 00:55:02 +02:00
|
|
|
import 'account/account_dialog.dart';
|
|
|
|
import 'account/account.dart';
|
|
|
|
import 'account/account_detail.dart';
|
|
|
|
|
2023-06-14 02:46:11 +02:00
|
|
|
Future<void> main() async {
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
await EasyLocalization.ensureInitialized();
|
2023-06-17 03:33:37 +02:00
|
|
|
runApp(ChangeNotifierProvider(
|
|
|
|
create: (context) => ThemeManager(),
|
|
|
|
child: EasyLocalization(
|
|
|
|
supportedLocales: const [Locale('en', 'US'), Locale('de', 'DE')],
|
|
|
|
path: 'lib/assets/translations',
|
|
|
|
// <-- change the path of the translation files
|
|
|
|
fallbackLocale: const Locale('en', 'US'),
|
|
|
|
child: const FinancialPlannerApp()),
|
|
|
|
));
|
|
|
|
}
|
2023-06-15 00:55:02 +02:00
|
|
|
|
2023-06-14 00:26:04 +02:00
|
|
|
ThemeManager _themeManager = ThemeManager();
|
2023-06-12 20:53:03 +02:00
|
|
|
|
|
|
|
class FinancialPlannerApp extends StatelessWidget {
|
2023-06-14 00:26:04 +02:00
|
|
|
const FinancialPlannerApp({super.key});
|
|
|
|
|
2023-06-12 20:53:03 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-06-17 03:33:37 +02:00
|
|
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
|
|
|
|
overlays: [SystemUiOverlay.top]);
|
2023-06-12 20:53:03 +02:00
|
|
|
return MaterialApp(
|
2023-06-14 02:46:11 +02:00
|
|
|
localizationsDelegates: context.localizationDelegates,
|
|
|
|
supportedLocales: context.supportedLocales,
|
|
|
|
locale: context.locale,
|
2023-06-14 00:26:04 +02:00
|
|
|
debugShowCheckedModeBanner: false,
|
2023-06-14 02:46:11 +02:00
|
|
|
title: 'title'.tr(),
|
2023-06-14 00:26:04 +02:00
|
|
|
theme: lightTheme,
|
|
|
|
darkTheme: darkTheme,
|
2023-06-17 03:09:31 +02:00
|
|
|
themeMode: Provider.of<ThemeManager>(context).themeMode,
|
2023-06-14 00:26:04 +02:00
|
|
|
home: const HomePage(),
|
2023-06-12 20:53:03 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class HomePage extends StatefulWidget {
|
2023-06-14 00:26:04 +02:00
|
|
|
const HomePage({super.key});
|
|
|
|
|
2023-06-12 20:53:03 +02:00
|
|
|
@override
|
2023-06-14 00:26:04 +02:00
|
|
|
HomePageState createState() => HomePageState();
|
2023-06-12 20:53:03 +02:00
|
|
|
}
|
|
|
|
|
2023-06-14 00:26:04 +02:00
|
|
|
class HomePageState extends State<HomePage> {
|
2023-06-12 20:53:03 +02:00
|
|
|
List<Account> accounts = [];
|
2023-06-17 03:09:31 +02:00
|
|
|
String _selectedCurrency = "€";
|
2023-06-16 04:27:34 +02:00
|
|
|
|
|
|
|
Future<String> getCurrencyFromSharedPreferences(String key) async {
|
|
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
2023-06-17 03:09:31 +02:00
|
|
|
if (prefs.getString(key) == "Euro") {
|
|
|
|
_selectedCurrency = "€";
|
2023-06-16 04:27:34 +02:00
|
|
|
}
|
2023-06-17 03:09:31 +02:00
|
|
|
if (prefs.getString(key) == "Dollar") {
|
|
|
|
_selectedCurrency = r"$";
|
2023-06-16 04:27:34 +02:00
|
|
|
}
|
2023-06-17 03:09:31 +02:00
|
|
|
if (prefs.getString(key) == "CHF") {
|
|
|
|
_selectedCurrency = "CHF";
|
2023-06-16 04:27:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return prefs.getString(key) ?? 'Euro';
|
|
|
|
}
|
2023-06-12 20:53:03 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2023-06-14 00:26:04 +02:00
|
|
|
_themeManager.addListener(themeListener);
|
2023-06-16 04:27:34 +02:00
|
|
|
getCurrencyFromSharedPreferences("currency").then((value) {
|
2023-06-17 03:09:31 +02:00
|
|
|
setState(() {});
|
2023-06-16 04:27:34 +02:00
|
|
|
});
|
2023-06-12 20:53:03 +02:00
|
|
|
loadAccounts();
|
2023-06-14 00:26:04 +02:00
|
|
|
}
|
2023-06-15 00:55:02 +02:00
|
|
|
|
2023-06-14 00:26:04 +02:00
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_themeManager.removeListener(themeListener);
|
|
|
|
super.dispose();
|
2023-06-12 20:53:03 +02:00
|
|
|
}
|
|
|
|
|
2023-06-15 00:55:02 +02:00
|
|
|
themeListener() {
|
|
|
|
if (mounted) {
|
|
|
|
setState(() {});
|
2023-06-14 00:26:04 +02:00
|
|
|
}
|
|
|
|
}
|
2023-06-15 00:55:02 +02:00
|
|
|
|
2023-06-12 20:53:03 +02:00
|
|
|
Future<void> loadAccounts() async {
|
|
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
|
final accountList = prefs.getStringList('accounts') ?? [];
|
|
|
|
|
|
|
|
setState(() {
|
2023-06-15 00:55:02 +02:00
|
|
|
accounts = accountList
|
|
|
|
.map((accountJson) => Account.fromJson(accountJson))
|
|
|
|
.toList();
|
2023-06-12 20:53:03 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> saveAccounts() async {
|
|
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
2023-06-15 00:55:02 +02:00
|
|
|
List<String> accountJsonList =
|
2023-06-17 03:33:37 +02:00
|
|
|
accounts.map((account) => json.encode(account.toJson())).toList();
|
2023-06-12 20:53:03 +02:00
|
|
|
await prefs.setStringList('accounts', accountJsonList);
|
|
|
|
}
|
|
|
|
|
|
|
|
void addAccount(Account account) {
|
|
|
|
setState(() {
|
|
|
|
accounts.add(account);
|
|
|
|
saveAccounts();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void deleteAccount(Account account) {
|
|
|
|
setState(() {
|
|
|
|
accounts.remove(account);
|
|
|
|
saveAccounts();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateAccountBalance(Account account) {
|
|
|
|
setState(() {
|
|
|
|
saveAccounts();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-17 03:09:31 +02:00
|
|
|
Future<void> saveCurrencyToSharedPreferences(String key, String value) async {
|
|
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
|
await prefs.setString(key, value);
|
|
|
|
}
|
|
|
|
|
2023-06-12 20:53:03 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2023-06-17 03:09:31 +02:00
|
|
|
toolbarHeight: 70,
|
2023-06-14 00:26:04 +02:00
|
|
|
centerTitle: true,
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
elevation: 0,
|
2023-06-17 03:33:37 +02:00
|
|
|
leading: Padding(
|
2023-06-18 03:00:17 +02:00
|
|
|
padding: const EdgeInsets.only(left: 5),
|
2023-06-17 03:33:37 +02:00
|
|
|
child: Image.asset(
|
|
|
|
'lib/assets/mfa_logo.png',
|
|
|
|
width: 32,
|
|
|
|
height: 32,
|
|
|
|
)),
|
2023-06-14 02:46:11 +02:00
|
|
|
title: Text(
|
|
|
|
'title'.tr(),
|
2023-06-17 03:09:31 +02:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 18,
|
|
|
|
fontWeight: FontWeight.bold,
|
2023-06-17 03:33:37 +02:00
|
|
|
color: Theme.of(context).brightness == Brightness.dark
|
2023-06-17 03:09:31 +02:00
|
|
|
? Colors.white70
|
|
|
|
: Colors.black87),
|
2023-06-14 00:26:04 +02:00
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
Padding(
|
2023-06-17 03:09:31 +02:00
|
|
|
padding: const EdgeInsets.only(right: 16.0, top: 9, bottom: 0),
|
2023-06-14 00:26:04 +02:00
|
|
|
child: NeumorphicButton(
|
2023-06-17 03:09:31 +02:00
|
|
|
margin: const EdgeInsets.only(bottom: 16),
|
2023-06-14 02:46:11 +02:00
|
|
|
onPressed: () async {
|
2023-06-15 00:55:02 +02:00
|
|
|
await Navigator.push(
|
2023-06-14 00:26:04 +02:00
|
|
|
context,
|
2023-06-15 00:55:02 +02:00
|
|
|
MaterialPageRoute(builder: (context) => const Settings()),
|
2023-06-14 00:26:04 +02:00
|
|
|
);
|
2023-06-15 00:55:02 +02:00
|
|
|
setState(() {});
|
2023-06-14 00:26:04 +02:00
|
|
|
},
|
|
|
|
style: NeumorphicStyle(
|
|
|
|
shape: NeumorphicShape.convex,
|
2023-06-15 00:55:02 +02:00
|
|
|
boxShape: const NeumorphicBoxShape.circle(),
|
2023-06-17 03:09:31 +02:00
|
|
|
depth: 8,
|
2023-06-14 00:26:04 +02:00
|
|
|
intensity: 0.9,
|
2023-06-17 03:09:31 +02:00
|
|
|
shadowLightColor:
|
2023-06-17 03:33:37 +02:00
|
|
|
Theme.of(context).brightness == Brightness.light
|
|
|
|
? const NeumorphicStyle().shadowLightColor
|
|
|
|
: Theme.of(context).shadowColor,
|
|
|
|
shadowDarkColor: Theme.of(context).brightness == Brightness.dark
|
2023-06-17 03:09:31 +02:00
|
|
|
? const NeumorphicStyle().shadowDarkColor
|
|
|
|
: grey400,
|
2023-06-17 03:33:37 +02:00
|
|
|
color: Theme.of(context).brightness == Brightness.light
|
2023-06-17 03:09:31 +02:00
|
|
|
? grey200
|
|
|
|
: grey800,
|
2023-06-14 00:26:04 +02:00
|
|
|
),
|
2023-06-17 03:09:31 +02:00
|
|
|
child: Icon(Icons.settings,
|
2023-06-17 03:33:37 +02:00
|
|
|
color: Theme.of(context).unselectedWidgetColor),
|
2023-06-14 00:26:04 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2023-06-12 20:53:03 +02:00
|
|
|
),
|
2023-06-17 03:09:31 +02:00
|
|
|
body: Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 5),
|
|
|
|
child: ListView.builder(
|
|
|
|
physics: const BouncingScrollPhysics(),
|
|
|
|
itemCount: accounts.length,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
return GestureDetector(
|
|
|
|
onLongPress: () {
|
|
|
|
AwesomeDialog(
|
2023-06-18 03:00:17 +02:00
|
|
|
dialogBackgroundColor:
|
|
|
|
Theme.of(context).brightness == Brightness.dark
|
|
|
|
? Colors.grey[800]
|
|
|
|
: Colors.grey[200],
|
2023-06-17 03:09:31 +02:00
|
|
|
btnOkText: "Delete".tr(),
|
2023-06-18 03:00:17 +02:00
|
|
|
btnOkColor: Colors.red,
|
|
|
|
btnCancelColor:
|
|
|
|
Theme.of(context).brightness == Brightness.dark
|
|
|
|
? Colors.grey[500]
|
|
|
|
: Colors.grey[500],
|
2023-06-17 03:09:31 +02:00
|
|
|
context: context,
|
|
|
|
animType: AnimType.bottomSlide,
|
|
|
|
dialogType: DialogType.info,
|
|
|
|
title: 'deleteaccount'.tr(),
|
|
|
|
headerAnimationLoop: false,
|
|
|
|
desc: 'sure'.tr(),
|
|
|
|
btnCancelOnPress: () {},
|
|
|
|
btnOkOnPress: () {
|
|
|
|
deleteAccount(accounts[index]);
|
|
|
|
},
|
|
|
|
).show();
|
2023-06-15 00:55:02 +02:00
|
|
|
},
|
2023-06-17 03:09:31 +02:00
|
|
|
child: Neumorphic(
|
|
|
|
margin: const EdgeInsets.all(16),
|
|
|
|
style: NeumorphicStyle(
|
|
|
|
depth: 8,
|
|
|
|
intensity: 1,
|
|
|
|
shadowLightColor:
|
2023-06-17 03:33:37 +02:00
|
|
|
Theme.of(context).brightness == Brightness.light
|
|
|
|
? const NeumorphicStyle().shadowLightColor
|
|
|
|
: grey800,
|
2023-06-17 03:09:31 +02:00
|
|
|
shadowDarkColor:
|
2023-06-17 03:33:37 +02:00
|
|
|
Theme.of(context).brightness == Brightness.dark
|
|
|
|
? const NeumorphicStyle().shadowDarkColor
|
|
|
|
: Theme.of(context).shadowColor,
|
|
|
|
color: Theme.of(context).brightness == Brightness.light
|
2023-06-17 03:09:31 +02:00
|
|
|
? grey200
|
|
|
|
: grey800,
|
|
|
|
boxShape:
|
2023-06-17 03:33:37 +02:00
|
|
|
NeumorphicBoxShape.roundRect(BorderRadius.circular(15)),
|
2023-06-17 03:09:31 +02:00
|
|
|
),
|
|
|
|
child: ListTile(
|
|
|
|
title: Text(accounts[index].name),
|
|
|
|
subtitle: Text(
|
2023-06-17 03:33:37 +02:00
|
|
|
'${'balance'.tr()}: $_selectedCurrency${accounts[index].balance.toStringAsFixed(2)}'),
|
2023-06-17 03:09:31 +02:00
|
|
|
onTap: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
2023-06-17 03:33:37 +02:00
|
|
|
builder: (context) => AccountDetailPage(
|
|
|
|
account: accounts[index],
|
|
|
|
updateAccountBalance: updateAccountBalance,
|
|
|
|
),
|
2023-06-17 03:09:31 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
)),
|
2023-06-14 00:26:04 +02:00
|
|
|
floatingActionButton: NeumorphicButton(
|
2023-06-12 20:53:03 +02:00
|
|
|
onPressed: () {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return AddAccountDialog(
|
|
|
|
addAccount: addAccount,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
2023-06-14 00:26:04 +02:00
|
|
|
style: NeumorphicStyle(
|
|
|
|
depth: 8,
|
|
|
|
intensity: 1,
|
2023-06-17 03:33:37 +02:00
|
|
|
shadowLightColor: Theme.of(context).brightness == Brightness.light
|
2023-06-17 03:09:31 +02:00
|
|
|
? const NeumorphicStyle().shadowLightColor
|
2023-06-17 03:33:37 +02:00
|
|
|
: Theme.of(context).shadowColor,
|
|
|
|
shadowDarkColor: Theme.of(context).brightness == Brightness.dark
|
2023-06-17 03:09:31 +02:00
|
|
|
? const NeumorphicStyle().shadowDarkColor
|
|
|
|
: grey400,
|
2023-06-17 03:33:37 +02:00
|
|
|
color: Theme.of(context).brightness == Brightness.light
|
2023-06-17 03:09:31 +02:00
|
|
|
? grey200
|
|
|
|
: grey800,
|
2023-06-14 00:26:04 +02:00
|
|
|
boxShape: const NeumorphicBoxShape.circle(),
|
|
|
|
),
|
2023-06-17 03:09:31 +02:00
|
|
|
child: Icon(
|
2023-06-14 00:26:04 +02:00
|
|
|
Icons.add,
|
2023-06-15 00:55:02 +02:00
|
|
|
size: 60,
|
2023-06-17 03:33:37 +02:00
|
|
|
color: Theme.of(context).brightness == Brightness.light
|
2023-06-17 03:09:31 +02:00
|
|
|
? Colors.black12
|
|
|
|
: Colors.white12,
|
2023-06-14 00:26:04 +02:00
|
|
|
),
|
2023-06-12 20:53:03 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|