76 lines
2.3 KiB
Dart
76 lines
2.3 KiB
Dart
import 'package:drift/drift.dart' show Value;
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get_it/get_it.dart';
|
|
import 'package:okane/database/sqlite.dart';
|
|
import 'package:okane/i18n/strings.g.dart';
|
|
import 'package:okane/ui/state/core.dart';
|
|
|
|
class AddBudgetPopup extends StatefulWidget {
|
|
final VoidCallback onDone;
|
|
|
|
const AddBudgetPopup({super.key, required this.onDone});
|
|
|
|
@override
|
|
AddBudgetState createState() => AddBudgetState();
|
|
}
|
|
|
|
class AddBudgetState extends State<AddBudgetPopup> {
|
|
final _budgetNameEditController = TextEditingController();
|
|
final _budgetIncomeEditController = TextEditingController();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
TextField(
|
|
decoration: InputDecoration(
|
|
hintText: t.pages.budgets.addBudget.budgetNameHint,
|
|
),
|
|
controller: _budgetNameEditController,
|
|
),
|
|
|
|
TextField(
|
|
decoration: InputDecoration(
|
|
hintText: t.pages.budgets.addBudget.income,
|
|
),
|
|
controller: _budgetIncomeEditController,
|
|
keyboardType: TextInputType.numberWithOptions(
|
|
signed: false,
|
|
decimal: true,
|
|
),
|
|
),
|
|
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
OutlinedButton(
|
|
onPressed: () async {
|
|
if (_budgetNameEditController.text.isEmpty ||
|
|
_budgetIncomeEditController.text.isEmpty) {
|
|
return;
|
|
}
|
|
|
|
final bloc = GetIt.I.get<CoreCubit>();
|
|
await GetIt.I.get<OkaneDatabase>().budgetsDao.upsertBudget(
|
|
BudgetsCompanion(
|
|
name: Value(_budgetNameEditController.text),
|
|
period: Value(BudgetPeriod.month),
|
|
includeOtherSpendings: Value(false),
|
|
income: Value(
|
|
double.parse(_budgetIncomeEditController.text),
|
|
),
|
|
accountId: Value(bloc.activeAccount!.id),
|
|
),
|
|
);
|
|
widget.onDone();
|
|
},
|
|
child: Text(t.modals.add),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|