-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
228 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'package:wealth_wave/domain/models/expense.dart'; | ||
|
||
class ExpenseVO { | ||
final int id; | ||
final double amount; | ||
final String? description; | ||
final DateTime createdOn; | ||
final List<String> tags; | ||
|
||
ExpenseVO._( | ||
{required this.id, | ||
required this.description, | ||
required this.amount, | ||
required this.createdOn, | ||
required this.tags}); | ||
|
||
factory ExpenseVO.from({required final Expense expense}) { | ||
return ExpenseVO._( | ||
id: expense.id, | ||
description: expense.description, | ||
amount: expense.amount, | ||
createdOn: expense.createdOn, | ||
tags: expense.tags); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'package:wealth_wave/core/presenter.dart'; | ||
import 'package:wealth_wave/domain/services/expense_service.dart'; | ||
import 'package:wealth_wave/ui/models/expense_vo.dart'; | ||
|
||
class MonthlyExpensePresenter extends Presenter<MonthlyExpenseViewState> { | ||
final DateTime _monthDate; | ||
final ExpenseService _expenseService; | ||
|
||
MonthlyExpensePresenter( | ||
{required final DateTime monthDate, final ExpenseService? expenseService}) | ||
: _monthDate = monthDate, | ||
_expenseService = expenseService ?? ExpenseService(), | ||
super(MonthlyExpenseViewState()); | ||
|
||
void getExpenses() { | ||
_expenseService | ||
.getExpensesForMonthDate(monthDate: _monthDate) | ||
.then((expenses) => expenses | ||
.map((expense) => ExpenseVO.from(expense: expense)) | ||
.toList()) | ||
.then((expenses) => updateViewState((viewState) { | ||
viewState.expenses = expenses; | ||
})); | ||
} | ||
|
||
void deleteExpense({required final int id}) { | ||
_expenseService.deleteBy(id: id).then((_) => getExpenses()); | ||
} | ||
} | ||
|
||
class MonthlyExpenseViewState { | ||
List<ExpenseVO> expenses = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:wealth_wave/core/page_state.dart'; | ||
import 'package:wealth_wave/ui/app_dimen.dart'; | ||
import 'package:wealth_wave/ui/models/expense_vo.dart'; | ||
import 'package:wealth_wave/ui/presentation/monthly_expense_presenter.dart'; | ||
import 'package:wealth_wave/ui/widgets/create_expense_dialog.dart'; | ||
import 'package:wealth_wave/utils/ui_utils.dart'; | ||
|
||
Future<void> showViewMonthlyExpensesDialog( | ||
{required final BuildContext context, required final DateTime monthDate}) { | ||
return showDialog( | ||
context: context, | ||
builder: (context) => _MonthlyExpensesDialog( | ||
monthDate: monthDate, | ||
)); | ||
} | ||
|
||
class _MonthlyExpensesDialog extends StatefulWidget { | ||
final DateTime monthDate; | ||
|
||
const _MonthlyExpensesDialog({required this.monthDate}); | ||
|
||
@override | ||
State<_MonthlyExpensesDialog> createState() => _MonthlyExpensesPage(); | ||
} | ||
|
||
class _MonthlyExpensesPage extends PageState<MonthlyExpenseViewState, | ||
_MonthlyExpensesDialog, MonthlyExpensePresenter> { | ||
@override | ||
void initState() { | ||
super.initState(); | ||
presenter.getExpenses(); | ||
} | ||
|
||
@override | ||
Widget buildWidget(BuildContext context, MonthlyExpenseViewState snapshot) { | ||
return AlertDialog( | ||
title: const Text('Expenses'), | ||
content: SizedBox( | ||
width: double.maxFinite, | ||
child: ListView.builder( | ||
shrinkWrap: true, | ||
itemCount: snapshot.expenses.length, | ||
itemBuilder: (context, index) { | ||
ExpenseVO expense = snapshot.expenses[index]; | ||
return ListTile( | ||
title: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Row( | ||
children: [ | ||
Text(formatDate(expense.createdOn)), | ||
const Text(' | '), | ||
Text(expense.description ?? ''), | ||
], | ||
), | ||
const SizedBox( | ||
height: AppDimen.minPadding), // Add some spacing | ||
Text('Amount: ${formatToCurrency(expense.amount)}'), | ||
], | ||
), | ||
trailing: Row(mainAxisSize: MainAxisSize.min, children: [ | ||
IconButton( | ||
icon: const Icon(Icons.edit), | ||
onPressed: () { | ||
showCreateExpenseDialog( | ||
context: context, expenseIdTOUpdate: expense.id) | ||
.then((value) => presenter.getExpenses()); | ||
}, | ||
), | ||
IconButton( | ||
icon: const Icon(Icons.delete), | ||
onPressed: () { | ||
presenter.deleteExpense(id: expense.id); | ||
}, | ||
) | ||
]), | ||
); | ||
}, | ||
)), | ||
actions: <Widget>[ | ||
OutlinedButton( | ||
child: const Text('Close'), | ||
onPressed: () { | ||
Navigator.of(context).pop(); | ||
}, | ||
), | ||
OutlinedButton( | ||
child: const Text('Add Expense'), | ||
onPressed: () { | ||
showCreateExpenseDialog(context: context) | ||
.then((value) => presenter.getExpenses()); | ||
}, | ||
), | ||
], | ||
); | ||
} | ||
|
||
@override | ||
MonthlyExpensePresenter initializePresenter() { | ||
return MonthlyExpensePresenter(monthDate: widget.monthDate); | ||
} | ||
} |