Start migration to sqlite using drift
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
import 'package:drift/drift.dart' show Value;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:okane/database/collections/beneficiary.dart';
|
||||
import 'package:okane/database/collections/budget.dart';
|
||||
import 'package:okane/database/collections/loan.dart';
|
||||
import 'package:okane/database/database.dart';
|
||||
import 'package:okane/database/sqlite.dart';
|
||||
import 'package:okane/i18n/strings.g.dart';
|
||||
import 'package:okane/ui/state/core.dart';
|
||||
import 'package:searchfield/searchfield.dart';
|
||||
@@ -47,7 +45,7 @@ class AddBudgetState extends State<AddLoanPopup> {
|
||||
.where((el) {
|
||||
final bloc = GetIt.I.get<CoreCubit>();
|
||||
if (el.type == BeneficiaryType.account) {
|
||||
return el.account.value?.id.toInt() ==
|
||||
return el.accountId ==
|
||||
bloc.activeAccount?.id.toInt();
|
||||
}
|
||||
return true;
|
||||
@@ -79,6 +77,7 @@ class AddBudgetState extends State<AddLoanPopup> {
|
||||
return;
|
||||
}
|
||||
|
||||
final db = GetIt.I.get<OkaneDatabase>();
|
||||
Beneficiary? beneficiary = _selectedBeneficiary?.item;
|
||||
if (beneficiary == null ||
|
||||
getBeneficiaryName(beneficiary) != beneficiaryName) {
|
||||
@@ -87,42 +86,49 @@ class AddBudgetState extends State<AddLoanPopup> {
|
||||
context: context,
|
||||
builder:
|
||||
(context) => AlertDialog(
|
||||
title: Text(t.common.beneficiary.addBeneficiary.title),
|
||||
content: Text(
|
||||
t.common.beneficiary.addBeneficiary.body(name: beneficiaryName),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(
|
||||
textStyle: Theme.of(context).textTheme.labelLarge,
|
||||
title: Text(
|
||||
t.common.beneficiary.addBeneficiary.title,
|
||||
),
|
||||
child: Text(t.modals.add),
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
),
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(
|
||||
textStyle: Theme.of(context).textTheme.labelLarge,
|
||||
content: Text(
|
||||
t.common.beneficiary.addBeneficiary.body(
|
||||
name: beneficiaryName,
|
||||
),
|
||||
),
|
||||
child: Text(t.modals.cancel),
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
actions: [
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(
|
||||
textStyle:
|
||||
Theme.of(context).textTheme.labelLarge,
|
||||
),
|
||||
child: Text(t.modals.add),
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
),
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(
|
||||
textStyle:
|
||||
Theme.of(context).textTheme.labelLarge,
|
||||
),
|
||||
child: Text(t.modals.cancel),
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (result == null || !result) {
|
||||
return;
|
||||
}
|
||||
|
||||
beneficiary =
|
||||
Beneficiary()
|
||||
..name = beneficiaryName
|
||||
..type = BeneficiaryType.other;
|
||||
await upsertBeneficiary(beneficiary);
|
||||
beneficiary = await db.beneficiariesDao.upsertBeneficiary(
|
||||
BeneficiariesCompanion(
|
||||
name: Value(beneficiaryName),
|
||||
type: Value(BeneficiaryType.other),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final loan =
|
||||
Loan()..beneficiary.value = beneficiary;
|
||||
await upsertLoan(loan);
|
||||
await db.loansDao.upsertLoan(
|
||||
LoansCompanion(beneficiaryId: Value(beneficiary.id)),
|
||||
);
|
||||
widget.onDone();
|
||||
},
|
||||
child: Text(t.modals.add),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:drift/drift.dart' show Value;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:okane/database/collections/loan.dart';
|
||||
import 'package:okane/database/database.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/utils.dart';
|
||||
|
||||
@@ -9,7 +10,7 @@ enum LoanChangeType { owe, loan }
|
||||
class AddLoanChangePopup extends StatefulWidget {
|
||||
final VoidCallback onDone;
|
||||
|
||||
final Loan loan;
|
||||
final LoanDto loan;
|
||||
|
||||
const AddLoanChangePopup({
|
||||
super.key,
|
||||
@@ -84,13 +85,14 @@ class AddLoanPopupState extends State<AddLoanChangePopup> {
|
||||
LoanChangeType.owe => -1,
|
||||
LoanChangeType.loan => 1,
|
||||
};
|
||||
final loanChange =
|
||||
LoanChange()
|
||||
..amount = sign * double.parse(_amountController.text).abs()
|
||||
..date = DateTime.now();
|
||||
await upsertLoanChange(loanChange);
|
||||
widget.loan.changes.add(loanChange);
|
||||
await upsertLoan(widget.loan);
|
||||
await GetIt.I.get<OkaneDatabase>().loansDao.upsertLoanChange(
|
||||
LoanChangesCompanion(
|
||||
amount: Value(
|
||||
sign * double.parse(_amountController.text).abs(),
|
||||
),
|
||||
date: Value(DateTime.now()),
|
||||
),
|
||||
);
|
||||
widget.onDone();
|
||||
},
|
||||
child: Text(t.modals.add),
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:grouped_list/grouped_list.dart';
|
||||
import 'package:okane/database/collections/loan.dart';
|
||||
import 'package:okane/database/database.dart';
|
||||
import 'package:okane/database/sqlite.dart';
|
||||
import 'package:okane/ui/pages/loans/add_loan_change.dart';
|
||||
import 'package:okane/ui/state/core.dart';
|
||||
import 'package:okane/ui/utils.dart';
|
||||
@@ -35,6 +35,7 @@ class LoanDetailsPage extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Expanded(
|
||||
child: BlocBuilder<CoreCubit, CoreState>(
|
||||
builder: (context, state) {
|
||||
@@ -55,11 +56,10 @@ class LoanDetailsPage extends StatelessWidget {
|
||||
child: Row(
|
||||
children: [
|
||||
ImageWrapper(
|
||||
title: state.activeLoan!.beneficiary.value!.name,
|
||||
path:
|
||||
state.activeLoan!.beneficiary.value!.imagePath,
|
||||
title: state.activeLoan!.beneficiary.name,
|
||||
path: state.activeLoan!.beneficiary.imagePath,
|
||||
),
|
||||
Text(state.activeLoan!.beneficiary.value!.name),
|
||||
Text(state.activeLoan!.beneficiary.name),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -145,11 +145,10 @@ class LoanDetailsPage extends StatelessWidget {
|
||||
color: Colors.red,
|
||||
),
|
||||
onPressed: () async {
|
||||
state.activeLoan!.changes.remove(
|
||||
item,
|
||||
);
|
||||
await deleteLoanChange(item);
|
||||
await upsertLoan(state.activeLoan!);
|
||||
await GetIt.I
|
||||
.get<OkaneDatabase>()
|
||||
.loansDao
|
||||
.deleteLoanChange(item.id);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:okane/database/database.dart';
|
||||
import 'package:okane/screen.dart';
|
||||
import 'package:okane/ui/pages/loans/add_loan.dart';
|
||||
import 'package:okane/ui/state/core.dart';
|
||||
@@ -21,7 +20,7 @@ class LoanListPage extends StatelessWidget {
|
||||
itemCount: state.loans.length,
|
||||
itemBuilder: (context, index) {
|
||||
final item = state.loans[index];
|
||||
final beneficiary = item.beneficiary.value!;
|
||||
final beneficiary = item.beneficiary;
|
||||
return ListTile(
|
||||
leading: ImageWrapper(
|
||||
title: beneficiary.name,
|
||||
@@ -45,7 +44,8 @@ class LoanListPage extends StatelessWidget {
|
||||
return;
|
||||
}
|
||||
|
||||
await deleteLoan(item);
|
||||
// TODO
|
||||
// await deleteLoan(item);
|
||||
},
|
||||
icon: Icon(Icons.delete, color: Colors.red),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user