diff --git a/lib/pages/accounts/add_account.dart b/lib/pages/accounts/add_account.dart index 67b578f..c554b5d 100644 --- a/lib/pages/accounts/add_account.dart +++ b/lib/pages/accounts/add_account.dart @@ -1,5 +1,6 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../../providers/accounts_provider.dart'; import '../../constants/constants.dart'; @@ -17,6 +18,7 @@ class AddAccount extends ConsumerStatefulWidget { class _AddAccountState extends ConsumerState with Functions { final TextEditingController nameController = TextEditingController(); + final TextEditingController startingValueController = TextEditingController(); @override void dispose() { @@ -24,6 +26,7 @@ class _AddAccountState extends ConsumerState with Functions { ref.invalidate(accountNameProvider); ref.invalidate(accountIconProvider); ref.invalidate(accountColorProvider); + ref.invalidate(accountStartingValueProvider); ref.invalidate(accountMainSwitchProvider); ref.invalidate(countNetWorthSwitchProvider); super.dispose(); @@ -234,6 +237,56 @@ class _AddAccountState extends ConsumerState with Functions { ], ), ), + + if (selectedAccount == null) + Container( + width: double.infinity, + margin: const EdgeInsets.fromLTRB(16, 24, 16, 0), + padding: const EdgeInsets.fromLTRB(16, 12, 16, 0), + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.surface, + borderRadius: BorderRadius.circular(4), + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + "STARTING VALUE", + style: Theme.of(context) + .textTheme + .labelLarge! + .copyWith( + color: Theme.of(context).colorScheme.primary), + ), + TextField( + controller: startingValueController, + decoration: InputDecoration( + hintText: "Initial balance", + suffixText: "€", + hintStyle: Theme.of(context) + .textTheme + .titleLarge! + .copyWith(color: grey2), + border: InputBorder.none, + contentPadding: const EdgeInsets.all(0), + ), + keyboardType: TextInputType.number, + inputFormatters: [ + FilteringTextInputFormatter.allow( + RegExp(r'[0-9,]')), + ], + style: Theme.of(context) + .textTheme + .titleLarge! + .copyWith(color: grey1), + onChanged: (value) => ref + .read(accountStartingValueProvider.notifier) + .state = currencyToNum(value), + ) + ], + ), + ), + Container( width: double.infinity, margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 24), diff --git a/lib/providers/accounts_provider.dart b/lib/providers/accounts_provider.dart index 75e33a5..fba0076 100644 --- a/lib/providers/accounts_provider.dart +++ b/lib/providers/accounts_provider.dart @@ -8,6 +8,7 @@ final selectedAccountProvider = StateProvider((ref) => null); final accountNameProvider = StateProvider((ref) => null); final accountIconProvider = StateProvider((ref) => accountIconList.keys.first); final accountColorProvider = StateProvider((ref) => 0); +final accountStartingValueProvider = StateProvider((ref) => null); final accountMainSwitchProvider = StateProvider((ref) => false); final countNetWorthSwitchProvider = StateProvider((ref) => true); @@ -35,7 +36,7 @@ class AsyncAccountsNotifier extends AsyncNotifier> { name: ref.read(accountNameProvider)!, symbol: ref.read(accountIconProvider), color: ref.read(accountColorProvider), - startingValue: 0, + startingValue: ref.read(accountStartingValueProvider) ?? 0, active: true, mainAccount: ref.read(accountMainSwitchProvider), ); @@ -69,6 +70,7 @@ class AsyncAccountsNotifier extends AsyncNotifier> { ref.read(accountNameProvider.notifier).state = account.name; ref.read(accountIconProvider.notifier).state = account.symbol; ref.read(accountColorProvider.notifier).state = account.color; + ref.read(accountStartingValueProvider.notifier).state = account.startingValue; ref.read(accountMainSwitchProvider.notifier).state = account.mainAccount; }