Updates from idk when...
This commit is contained in:
@@ -10,21 +10,23 @@ import '../../../global/styles.dart';
|
||||
import '../../../global/widgets/ui_button.dart';
|
||||
import '../../../models/budget_category_model.dart';
|
||||
import '../../../models/transaction_model.dart';
|
||||
import '../../../models/user.dart';
|
||||
|
||||
class AddTransactionDialog extends ConsumerStatefulWidget {
|
||||
const AddTransactionDialog({super.key, this.transaction});
|
||||
class TransactionDialog extends ConsumerStatefulWidget {
|
||||
const TransactionDialog({super.key, this.transaction});
|
||||
|
||||
final Transaction? transaction;
|
||||
|
||||
@override
|
||||
ConsumerState<AddTransactionDialog> createState() =>
|
||||
ConsumerState<TransactionDialog> createState() =>
|
||||
_AddTransactionDialogState();
|
||||
}
|
||||
|
||||
class _AddTransactionDialogState extends ConsumerState<AddTransactionDialog> {
|
||||
class _AddTransactionDialogState extends ConsumerState<TransactionDialog> {
|
||||
late DateTime selectedDate;
|
||||
late final TextEditingController amountController;
|
||||
late final TextEditingController memoController;
|
||||
User? user;
|
||||
|
||||
final amountFocusNode = FocusNode();
|
||||
final memoFocusNode = FocusNode();
|
||||
@@ -49,11 +51,20 @@ class _AddTransactionDialogState extends ConsumerState<AddTransactionDialog> {
|
||||
if (categories.isNotEmpty) {
|
||||
selectedBudgetCategory = categories.first;
|
||||
}
|
||||
final u = ref.read(userProvider);
|
||||
if (u == null) {
|
||||
WidgetsBinding.instance.addPostFrameCallback(
|
||||
(_) => ref.read(jwtProvider.notifier).revokeToken());
|
||||
} else {
|
||||
user = u;
|
||||
}
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (user == null) return Container();
|
||||
final List<BudgetCategory> budgetCategories =
|
||||
ref.read(budgetCategoriesProvider);
|
||||
return SizedBox(
|
||||
@@ -274,7 +285,7 @@ class _AddTransactionDialogState extends ConsumerState<AddTransactionDialog> {
|
||||
Map<String, dynamic>? data;
|
||||
if (widget.transaction != null) {
|
||||
data = await ref.read(apiProvider.notifier).put(
|
||||
path: 'transactions',
|
||||
path: 'transaction',
|
||||
data: Transaction.copyWith(widget.transaction!, {
|
||||
'memo': memoController.text.isNotEmpty ? memoController.text : null,
|
||||
'amount': double.parse(amountController.text),
|
||||
@@ -284,14 +295,14 @@ class _AddTransactionDialogState extends ConsumerState<AddTransactionDialog> {
|
||||
}).toJson());
|
||||
} else {
|
||||
data = await ref.read(apiProvider.notifier).post(
|
||||
path: 'transactions',
|
||||
path: 'transaction',
|
||||
data: Transaction(
|
||||
amount: double.parse(amountController.text),
|
||||
addedByUserId: 1,
|
||||
createdByUserId: user!.id!,
|
||||
budgetCategoryId: transactionType == TransactionType.income
|
||||
? null
|
||||
: selectedBudgetCategory.id,
|
||||
budgetId: 1,
|
||||
budgetId: user!.budgetId,
|
||||
date: DateTime.now(),
|
||||
type: transactionType,
|
||||
memo: memoController.text.isNotEmpty
|
||||
|
||||
Reference in New Issue
Block a user