Skip to content

Commit

Permalink
Merge pull request #70 from enrique-lozano/feat/finance-health-stats
Browse files Browse the repository at this point in the history
Add more finance health data to the user
  • Loading branch information
enrique-lozano authored Nov 1, 2023
2 parents d840606 + 1d28424 commit e5c50ff
Show file tree
Hide file tree
Showing 9 changed files with 847 additions and 326 deletions.
143 changes: 24 additions & 119 deletions lib/app/home/home.page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:monekin/app/accounts/account_form.dart';
import 'package:monekin/app/home/widgets/home_drawer.dart';
import 'package:monekin/app/home/widgets/income_or_expense_card.dart';
import 'package:monekin/app/stats/widgets/balance_bar_chart_small.dart';
import 'package:monekin/app/stats/widgets/finance_health/finance_health_main_info.dart';
import 'package:monekin/app/stats/widgets/fund_evolution_line_chart.dart';
import 'package:monekin/app/stats/widgets/movements_distribution/chart_by_categories.dart';
import 'package:monekin/app/transactions/form/transaction_form.page.dart';
Expand All @@ -15,7 +16,6 @@ import 'package:monekin/core/models/account/account.dart';
import 'package:monekin/core/models/transaction/transaction.dart';
import 'package:monekin/core/presentation/responsive/breakpoints.dart';
import 'package:monekin/core/presentation/responsive/responsive_row_column.dart';
import 'package:monekin/core/presentation/widgets/animated_progress_bar.dart';
import 'package:monekin/core/presentation/widgets/card_with_header.dart';
import 'package:monekin/core/presentation/widgets/number_ui_formatters/currency_displayer.dart';
import 'package:monekin/core/presentation/widgets/skeleton.dart';
Expand Down Expand Up @@ -404,127 +404,32 @@ class _HomePageState extends State<HomePage> {
rowFit: FlexFit.tight,
child: CardWithHeader(
title: t.financial_health.display,
onHeaderButtonClick: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
const StatsPage(initialIndex: 0),
),
),
bodyPadding: const EdgeInsets.only(right: 8),
body: StreamBuilder(
stream: _accountsStream,
builder: (context, snapshot) {
if (!snapshot.hasData) {
return const LinearProgressIndicator();
}

final accounts = snapshot.data!;
stream: FinanceHealthService().getHealthyValue(
filters: TransactionFilters(
minDate: dateRangeService.startDate,
maxDate: dateRangeService.endDate,
),
),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return const LinearProgressIndicator();
}

return Padding(
padding: const EdgeInsets.all(16),
child: StreamBuilder(
initialData: 0.0,
stream: FinanceHealthService()
.getHealthyValue(
accounts: accounts,
startDate: dateRangeService.startDate,
endDate: dateRangeService.endDate,
),
builder: (context, snapshot) {
Color getHealthyValueColor(
double healthyValue) =>
HSLColor.fromAHSL(
1, healthyValue, 1, 0.35)
.toColor();
final financeHealthData = snapshot.data!;

return ConstrainedBox(
constraints: BoxConstraints(
maxHeight:
BreakPoint.of(context)
.isLargerThan(
BreakpointID.md)
? 265
: 180),
child: Row(
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
AnimatedProgressBar(
value: snapshot.data! / 100,
direction: Axis.vertical,
width: 16,
color: getHealthyValueColor(
snapshot.data!),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment:
CrossAxisAlignment
.start,
mainAxisAlignment:
MainAxisAlignment
.spaceEvenly,
children: [
Column(
crossAxisAlignment:
CrossAxisAlignment
.start,
children: [
Row(
crossAxisAlignment:
CrossAxisAlignment
.baseline,
textBaseline:
TextBaseline
.alphabetic,
children: [
Text(
snapshot.data!
.toStringAsFixed(
0),
style: Theme.of(
context)
.textTheme
.headlineMedium!
.copyWith(
color: getHealthyValueColor(
snapshot.data!),
fontWeight:
FontWeight.w700,
),
),
const Text(
' / 100')
]),
Text(
FinanceHealthService()
.getHealthyValueReviewTitle(
context,
snapshot
.data!),
style: Theme.of(
context)
.textTheme
.titleMedium!
.copyWith(
color: getHealthyValueColor(
snapshot
.data!),
fontWeight:
FontWeight
.w700,
),
),
],
),
Text(
FinanceHealthService()
.getHealthyValueReviewDescr(
context,
snapshot.data!),
),
],
),
)
],
),
);
}));
}),
return FinanceHealthMainInfo(
financeHealthData: financeHealthData);
},
),
),
),
ResponsiveRowColumnItem(
Expand Down
44 changes: 26 additions & 18 deletions lib/app/stats/stats_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:monekin/app/stats/footer_segmented_calendar_button.dart';
import 'package:monekin/app/stats/widgets/balance_bar_chart.dart';
import 'package:monekin/app/stats/widgets/finance_health_details.dart';
import 'package:monekin/app/stats/widgets/fund_evolution_line_chart.dart';
import 'package:monekin/app/stats/widgets/income_expense_comparason.dart';
import 'package:monekin/app/stats/widgets/movements_distribution/chart_by_categories.dart';
Expand Down Expand Up @@ -68,7 +69,7 @@ class _StatsPageState extends State<StatsPage> {

return DefaultTabController(
initialIndex: widget.initialIndex,
length: 3,
length: 4,
child: Scaffold(
appBar: AppBar(
title: Text(t.stats.title),
Expand All @@ -92,6 +93,7 @@ class _StatsPageState extends State<StatsPage> {
icon: const Icon(Icons.filter_alt_outlined)),
],
bottom: TabBar(tabs: [
Tab(text: t.financial_health.display),
Tab(text: t.stats.distribution),
Tab(text: t.stats.balance),
Tab(text: t.stats.cash_flow),
Expand Down Expand Up @@ -123,6 +125,14 @@ class _StatsPageState extends State<StatsPage> {
],
Expanded(
child: TabBarView(children: [
buildContainerWithPadding(
[
FinanceHealthDetails(
filters: filters.copyWith(
minDate: currentStartDate, maxDate: currentEndDate),
)
],
),
buildContainerWithPadding([
CardWithHeader(
title: t.stats.by_categories,
Expand All @@ -145,25 +155,23 @@ class _StatsPageState extends State<StatsPage> {
),
),
]),
buildContainerWithPadding(
[
CardWithHeader(
title: t.stats.balance_evolution,
body: FundEvolutionLineChart(
showBalanceHeader: true,
startDate: currentStartDate,
endDate: currentEndDate,
dateRange: currentDateRange,
filters: filters,
),
),
const SizedBox(height: 16),
AllAccountBalancePage(
date: currentEndDate ?? DateTime.now(),
buildContainerWithPadding([
CardWithHeader(
title: t.stats.balance_evolution,
body: FundEvolutionLineChart(
showBalanceHeader: true,
startDate: currentStartDate,
endDate: currentEndDate,
dateRange: currentDateRange,
filters: filters,
),
],
),
),
const SizedBox(height: 16),
AllAccountBalancePage(
date: currentEndDate ?? DateTime.now(),
filters: filters,
),
]),
buildContainerWithPadding([
CardWithHeader(
title: t.stats.cash_flow,
Expand Down
73 changes: 73 additions & 0 deletions lib/app/stats/widgets/finance_health/finance_health_main_info.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import 'package:flutter/material.dart';
import 'package:monekin/core/presentation/responsive/breakpoints.dart';
import 'package:monekin/core/presentation/widgets/animated_progress_bar.dart';
import 'package:monekin/core/services/finance_health_service.dart';

class FinanceHealthMainInfo extends StatelessWidget {
const FinanceHealthMainInfo({super.key, required this.financeHealthData});

final FinanceHealthData financeHealthData;

@override
Widget build(BuildContext context) {
return ConstrainedBox(
constraints: BoxConstraints(
maxHeight:
BreakPoint.of(context).isLargerThan(BreakpointID.md) ? 265 : 180),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
AnimatedProgressBar(
value: (financeHealthData.healthyScore ?? 20) / 100,
direction: Axis.vertical,
width: 16,
color: FinanceHealthData.getHealthyValueColor(
financeHealthData.healthyScore),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text.rich(
TextSpan(children: [
TextSpan(
text: financeHealthData.healthyScoreString(),
style: Theme.of(context)
.textTheme
.headlineLarge!
.copyWith(
color: FinanceHealthData.getHealthyValueColor(
financeHealthData.healthyScore),
fontWeight: FontWeight.w700,
),
),
const TextSpan(text: ' / 100'),
]),
),
Text(
financeHealthData.getHealthyScoreReviewTitle(context),
style: Theme.of(context).textTheme.titleMedium!.copyWith(
color: FinanceHealthData.getHealthyValueColor(
financeHealthData.healthyScore),
fontWeight: FontWeight.w700,
),
),
],
),
Text(
financeHealthData.getHealthyScoreReviewDescr(context),
style: Theme.of(context).textTheme.bodySmall,
),
],
),
)
],
),
);
}
}
Loading

0 comments on commit e5c50ff

Please sign in to comment.