mirror of
https://github.com/koloideal/Casha.git
synced 2026-08-08 17:51:14 +03:00
step
This commit is contained in:
@@ -80,13 +80,22 @@ class AddTransactionState {
|
||||
bool get isEditing => editingId != null;
|
||||
}
|
||||
|
||||
class AddTransactionNotifier extends StateNotifier<AddTransactionState> {
|
||||
AddTransactionNotifier(Transaction? initial)
|
||||
: super(
|
||||
initial != null
|
||||
? AddTransactionState.fromTransaction(initial)
|
||||
: AddTransactionState.empty(),
|
||||
);
|
||||
final addTransactionProvider = NotifierProvider.autoDispose
|
||||
.family<AddTransactionNotifier, AddTransactionState, Transaction?>(
|
||||
(initial) => AddTransactionNotifier(initial),
|
||||
);
|
||||
|
||||
class AddTransactionNotifier extends Notifier<AddTransactionState> {
|
||||
AddTransactionNotifier(this._initial);
|
||||
|
||||
final Transaction? _initial;
|
||||
|
||||
@override
|
||||
AddTransactionState build() {
|
||||
return _initial != null
|
||||
? AddTransactionState.fromTransaction(_initial!)
|
||||
: AddTransactionState.empty();
|
||||
}
|
||||
|
||||
void setAmount(double? v) => state = state.copyWith(amount: v);
|
||||
|
||||
@@ -123,11 +132,6 @@ class AddTransactionNotifier extends StateNotifier<AddTransactionState> {
|
||||
void reset() => state = AddTransactionState.empty();
|
||||
}
|
||||
|
||||
final addTransactionProvider = StateNotifierProvider.autoDispose
|
||||
.family<AddTransactionNotifier, AddTransactionState, Transaction?>(
|
||||
(ref, initial) => AddTransactionNotifier(initial),
|
||||
);
|
||||
|
||||
final availableCategoriesProvider = Provider.autoDispose
|
||||
.family<List<String>, Transaction?>((ref, initial) {
|
||||
final type = ref.watch(
|
||||
@@ -135,3 +139,4 @@ final availableCategoriesProvider = Provider.autoDispose
|
||||
);
|
||||
return AppCategories.forType(type);
|
||||
});
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
||||
|
||||
if (widget.initial!.category == 'Transfer') {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
final allTxs = ref.read(transactionsProvider).valueOrNull ?? [];
|
||||
final allTxs = ref.read(transactionsProvider).value ?? [];
|
||||
|
||||
if (widget.initial!.type == TransactionType.expense) {
|
||||
final counterpart = allTxs.firstWhereOrNull(
|
||||
@@ -271,7 +271,7 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
||||
currencyCode: currencyCode,
|
||||
accountId: state.selectedAccountId!,
|
||||
);
|
||||
await ref.read(transactionsProvider.notifier).update(updatedExpense);
|
||||
await ref.read(transactionsProvider.notifier).updateTransaction(updatedExpense);
|
||||
|
||||
if (_transferIncomeRecordId != null) {
|
||||
final updatedIncome = Transaction(
|
||||
@@ -285,7 +285,7 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
||||
currencyCode: currencyCode,
|
||||
accountId: state.toAccountId!,
|
||||
);
|
||||
await ref.read(transactionsProvider.notifier).update(updatedIncome);
|
||||
await ref.read(transactionsProvider.notifier).updateTransaction(updatedIncome);
|
||||
}
|
||||
|
||||
if (mounted) context.pop();
|
||||
@@ -349,7 +349,7 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
||||
);
|
||||
|
||||
if (state.isEditing) {
|
||||
await ref.read(transactionsProvider.notifier).update(tx);
|
||||
await ref.read(transactionsProvider.notifier).updateTransaction(tx);
|
||||
} else {
|
||||
final res = await ref.read(transactionsProvider.notifier).add(tx);
|
||||
|
||||
@@ -486,7 +486,7 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
||||
.delete(counterpartId);
|
||||
} else {
|
||||
final allTxs =
|
||||
ref.read(transactionsProvider).valueOrNull ??
|
||||
ref.read(transactionsProvider).value ??
|
||||
[];
|
||||
final oppositeType =
|
||||
widget.initial!.type ==
|
||||
|
||||
@@ -41,7 +41,7 @@ class AccountRow extends ConsumerWidget {
|
||||
final s = ref.watch(stringsProvider);
|
||||
final state = ref.watch(addTransactionProvider(initial));
|
||||
final accountsAsync = ref.watch(accountsProvider);
|
||||
final accounts = accountsAsync.valueOrNull ?? [];
|
||||
final accounts = accountsAsync.value ?? [];
|
||||
final isTransfer = state.type == TransactionType.transfer;
|
||||
|
||||
if (isTransfer && accounts.length == 2 && state.selectedAccountId != null) {
|
||||
|
||||
@@ -21,7 +21,7 @@ class TypeToggle extends ConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final accountsAsync = ref.watch(accountsProvider);
|
||||
final accounts = accountsAsync.valueOrNull ?? [];
|
||||
final accounts = accountsAsync.value ?? [];
|
||||
final transferDisabled = accounts.length <= 1;
|
||||
|
||||
return Container(
|
||||
|
||||
Reference in New Issue
Block a user