Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page to add/edit transactions and account page #118

Merged
merged 15 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/constants/functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import '../model/transaction.dart';

mixin Functions {
String numToCurrency(num? value) {
if(value == null) return '';
if (value == null) return '';
return value.toStringAsFixed(2).replaceAll(".", ",");
}

Expand All @@ -17,7 +17,7 @@ mixin Functions {
}

String dateToString(DateTime date) {
final format = DateFormat('E d MMMM', 'it_IT');
final format = DateFormat('E, d MMMM y');
return format.format(date);
}

Expand Down
59 changes: 21 additions & 38 deletions lib/custom_widgets/accounts_sum.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../constants/constants.dart';
import '../model/bank_account.dart';
import '../constants/functions.dart';
import '../constants/style.dart';
import 'account_modal.dart';
import '../../../providers/accounts_provider.dart';

/// This class shows account summaries in the dashboard
class AccountsSum extends StatelessWidget with Functions {
class AccountsSum extends ConsumerWidget with Functions {
final BankAccount account;

const AccountsSum({
Expand All @@ -16,7 +18,7 @@ class AccountsSum extends StatelessWidget with Functions {
}) : super(key: key);

@override
Widget build(BuildContext context) {
Widget build(BuildContext context, WidgetRef ref) {
return Container(
width: 160.0,
margin: const EdgeInsets.fromLTRB(0, 4, 16, 6),
Expand All @@ -34,35 +36,12 @@ class AccountsSum extends StatelessWidget with Functions {
color: Colors.transparent,
child: InkWell(
borderRadius: BorderRadius.circular(8),
onTap: () {
showModalBottomSheet(
backgroundColor: Colors.transparent,
context: context,
isScrollControlled: true,
isDismissible: true,
builder: (BuildContext buildContext) {
return DraggableScrollableSheet(
builder: (_, controller) => Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
color: const Color(0xff356CA3),
),
child: ListView(
controller: controller,
children: [
AccountDialog(
accountName: account.name,
amount: account.startingValue,
)
],
),
),
initialChildSize: 0.7,
minChildSize: 0.5,
maxChildSize: 1,
);
},
);
onTap: () async {
await ref
.read(accountsProvider.notifier)
.selectedAccount(account)
.whenComplete(
() => Navigator.of(context).pushNamed('/account'));
},
child: Container(
padding: const EdgeInsets.fromLTRB(12, 8, 12, 8),
Expand All @@ -76,20 +55,24 @@ class AccountsSum extends StatelessWidget with Functions {
),
child: Padding(
padding: const EdgeInsets.all(6.0),
child: Icon(accountIconList[account.symbol],
size: 20.0,
color: white), //capire se cambiare colore icona
child: Icon(
accountIconList[account.symbol],
size: 20.0,
color: white,
),
),
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(account.name,
style: Theme.of(context)
Text(
account.name,
style: Theme.of(context)
.textTheme
.bodyLarge!
.copyWith(color: darkBlue7)),//impostato manualmente darkBlue7, da rivedere
.copyWith(color: darkBlue7),
), // TODO: set dinamically instead of hardcoded
FutureBuilder<num?>(
future: BankAccountMethods().getAccountSum(account.id),
builder: (context, snapshot) {
Expand Down
36 changes: 10 additions & 26 deletions lib/custom_widgets/transactions_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../constants/constants.dart';
import '../pages/add_page/add_page.dart';
import '../providers/transactions_provider.dart';
import '../constants/functions.dart';
import '../model/bank_account.dart';
Expand Down Expand Up @@ -184,32 +183,17 @@ class TransactionRow extends ConsumerWidget with Functions {
color: Theme.of(context).colorScheme.primaryContainer,
child: InkWell(
onTap: () {
ref.read(selectedTransactionUpdateProvider.notifier).state = transaction;
ref.read(transactionsProvider.notifier).transactionUpdateState();
showModalBottomSheet(
backgroundColor: Colors.transparent,
context: context,
isScrollControlled: true,
isDismissible: true,
builder: (BuildContext buildContext) {
return DraggableScrollableSheet(
builder: (_, controller) => Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
color: Theme.of(context).colorScheme.background,
),
child: ListView(
controller: controller,
shrinkWrap: true,
children: const [AddPage()],
),
),
initialChildSize: 0.92,
minChildSize: 0.75,
maxChildSize: 0.92,
ref.read(selectedTransactionUpdateProvider.notifier).state =
transaction;
ref
.read(transactionsProvider.notifier)
.transactionUpdateState();
ref
.read(transactionsProvider.notifier)
.transactionUpdateState()
.whenComplete(
() => Navigator.of(context).pushNamed("/add-page"),
);
},
);
},
borderRadius: BorderRadius.vertical(
top: i == 0 ? const Radius.circular(8) : Radius.zero,
Expand Down
84 changes: 84 additions & 0 deletions lib/pages/account_page/account_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:fl_chart/fl_chart.dart';

import '../../providers/accounts_provider.dart';
import '../../custom_widgets/line_chart.dart';
import '../../constants/functions.dart';
import '../../constants/style.dart';

class AccountPage extends ConsumerStatefulWidget {
const AccountPage({Key? key}) : super(key: key);

@override
ConsumerState<ConsumerStatefulWidget> createState() => _AccountPage();
}

class _AccountPage extends ConsumerState<AccountPage> with Functions {
@override
Widget build(BuildContext context) {
final accountName = ref.read(accountNameProvider);
final accountAmount = ref.read(accountStartingValueProvider);

return Scaffold(
appBar: AppBar(
title: Text(accountName ?? "", style: const TextStyle(color: white)),
backgroundColor: blue5,
elevation: 0,
),
body: SingleChildScrollView(
child: Column(
children: [
Container(
padding: const EdgeInsets.symmetric(vertical: 12.0),
color: blue5,
child: Column(
children: [
Text(
numToCurrency(accountAmount),
style: const TextStyle(
color: white,
fontSize: 32.0,
fontFamily: 'SF Pro Text',
fontWeight: FontWeight.bold,
),
),
const Padding(padding: EdgeInsets.all(8.0)),
const LineChartWidget(
line1Data: [
FlSpot(0, 3),
FlSpot(1, 1.3),
FlSpot(2, -2),
FlSpot(3, -4.5),
FlSpot(4, -5),
FlSpot(5, -2.2),
FlSpot(6, -3.1),
FlSpot(7, -0.2),
FlSpot(8, -4),
FlSpot(9, -3),
FlSpot(10, -2),
FlSpot(11, -4),
FlSpot(12, 3),
FlSpot(13, 1.3),
FlSpot(14, -2),
FlSpot(15, -4.5),
FlSpot(16, 2.5),
],
colorLine1Data: Color(0xffffffff),
line2Data: <FlSpot>[],
colorLine2Data: Color(0xffffffff),
colorBackground: blue5,
maxY: 5.0,
minY: -5.0,
maxDays: 30.0,
),
],
),
),
// TODO: add list of transactions
],
),
),
);
}
}
Loading
Loading