feat(proj): init
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:please_pay_me/core/format/formatters.dart';
|
||||
import 'package:please_pay_me/features/budgets/budgets_controller.dart';
|
||||
import 'package:please_pay_me/features/expenses/expense_form_sheet.dart';
|
||||
import 'package:please_pay_me/features/journal/journal_controller.dart';
|
||||
import 'package:please_pay_me/ui/ui.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
/// Opens the expense form and keeps the journal in sync on success.
|
||||
Future<void> showExpenseFormSheet({
|
||||
required BuildContext context,
|
||||
required BudgetsController controller,
|
||||
}) async {
|
||||
final selected = controller.selected;
|
||||
final journal = context.read<JournalController>();
|
||||
|
||||
final saved = await showAppFormSheet<bool>(
|
||||
context: context,
|
||||
builder: (_) => ExpenseFormSheet(
|
||||
budgetName: selected?.budget.name,
|
||||
remainingToday: selected?.remainingToday,
|
||||
onSubmit: ({required amount, note, required spentAt}) => controller.addExpense(
|
||||
amount: amount,
|
||||
note: note,
|
||||
spentAt: spentAt,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if (saved != true) return;
|
||||
|
||||
await journal.load(silent: true);
|
||||
if (context.mounted) {
|
||||
await showAppToast(context, message: 'Трата записана');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> undoLastExpense({
|
||||
required BuildContext context,
|
||||
required BudgetsController controller,
|
||||
}) async {
|
||||
final journal = context.read<JournalController>();
|
||||
final confirmed = await showAppAlert(
|
||||
context: context,
|
||||
title: 'Отменить последнюю трату?',
|
||||
message: 'Операция будет удалена из текущего бюджета.',
|
||||
confirmLabel: 'Отменить трату',
|
||||
cancelLabel: 'Закрыть',
|
||||
destructive: true,
|
||||
);
|
||||
|
||||
if (confirmed != true) return;
|
||||
|
||||
final error = await controller.undoLastExpense();
|
||||
await journal.load(silent: true);
|
||||
|
||||
if (!context.mounted) return;
|
||||
|
||||
await showAppToast(
|
||||
context,
|
||||
message: error ?? 'Последняя трата удалена',
|
||||
icon: error == null
|
||||
? CupertinoIcons.arrow_uturn_left_circle_fill
|
||||
: CupertinoIcons.exclamationmark_circle_fill,
|
||||
);
|
||||
}
|
||||
|
||||
/// Shared row renderer so the journal and the overview look identical.
|
||||
String expenseTitle(String? note) => note?.trim().isNotEmpty == true ? note!.trim() : 'Без комментария';
|
||||
|
||||
String expenseAmount(double amount, {String currency = 'RUB'}) {
|
||||
return formatSignedMoney(amount, currency: currency);
|
||||
}
|
||||
Reference in New Issue
Block a user