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
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
69 changes: 29 additions & 40 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,22 +55,25 @@ class AccountsSum extends StatelessWidget with Functions {
),
child: Padding(
padding: const EdgeInsets.all(6.0),
child: Icon(accountIconList[account.symbol], size: 20.0, color: white),
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).textTheme.bodyLarge),
Text(account.name,
style: Theme.of(context).textTheme.bodyLarge),
FutureBuilder<num?>(
future: BankAccountMethods().getAccountSum(account.id),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
if (snapshot.connectionState ==
ConnectionState.waiting) {
// Show a loading indicator while waiting for the future to complete
return Transform.scale(
scale: 0.5,
child: CircularProgressIndicator(),
child: const CircularProgressIndicator(),
);
} else if (snapshot.hasError) {
// Show an error message if the future encounters an error
Expand All @@ -100,17 +82,24 @@ class AccountsSum extends StatelessWidget with Functions {
// Display the result once the future completes successfully
final accountSum = snapshot.data ?? 0;
return RichText(
textScaleFactor: MediaQuery.of(context).textScaleFactor,
textScaleFactor:
MediaQuery.of(context).textScaleFactor,
text: TextSpan(
children: [
TextSpan(
text: numToCurrency(accountSum),
style: Theme.of(context).textTheme.titleSmall,
style:
Theme.of(context).textTheme.titleSmall,
),
TextSpan(
text: "€",
style: Theme.of(context).textTheme.bodyMedium?.apply(
fontFeatures: [const FontFeature.subscripts()],
style: Theme.of(context)
.textTheme
.bodyMedium
?.apply(
fontFeatures: [
const FontFeature.subscripts()
],
),
),
],
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