Skip to content

Commit

Permalink
Merge pull request #109 from Paxol/account-starting-balance
Browse files Browse the repository at this point in the history
Starting balance field in account creation page
  • Loading branch information
mikev-cw authored Jul 13, 2023
2 parents 4e72dc4 + d8b3101 commit 6393061
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
53 changes: 53 additions & 0 deletions lib/pages/accounts/add_account.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -17,13 +18,15 @@ class AddAccount extends ConsumerStatefulWidget {

class _AddAccountState extends ConsumerState<AddAccount> with Functions {
final TextEditingController nameController = TextEditingController();
final TextEditingController startingValueController = TextEditingController();

@override
void dispose() {
ref.invalidate(selectedAccountProvider);
ref.invalidate(accountNameProvider);
ref.invalidate(accountIconProvider);
ref.invalidate(accountColorProvider);
ref.invalidate(accountStartingValueProvider);
ref.invalidate(accountMainSwitchProvider);
ref.invalidate(countNetWorthSwitchProvider);
super.dispose();
Expand Down Expand Up @@ -234,6 +237,56 @@ class _AddAccountState extends ConsumerState<AddAccount> 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: <TextInputFormatter>[
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),
Expand Down
4 changes: 3 additions & 1 deletion lib/providers/accounts_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ final selectedAccountProvider = StateProvider<BankAccount?>((ref) => null);
final accountNameProvider = StateProvider<String?>((ref) => null);
final accountIconProvider = StateProvider<String>((ref) => accountIconList.keys.first);
final accountColorProvider = StateProvider<int>((ref) => 0);
final accountStartingValueProvider = StateProvider<num?>((ref) => null);
final accountMainSwitchProvider = StateProvider<bool>((ref) => false);
final countNetWorthSwitchProvider = StateProvider<bool>((ref) => true);

Expand Down Expand Up @@ -35,7 +36,7 @@ class AsyncAccountsNotifier extends AsyncNotifier<List<BankAccount>> {
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),
);
Expand Down Expand Up @@ -69,6 +70,7 @@ class AsyncAccountsNotifier extends AsyncNotifier<List<BankAccount>> {
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;
}

Expand Down

0 comments on commit 6393061

Please sign in to comment.