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

Sadespresso/stats-tab-again-20250118 #273

Merged
merged 2 commits into from
Jan 23, 2025
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
114 changes: 63 additions & 51 deletions lib/routes/home/stats_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import "dart:ui";

import "package:auto_size_text/auto_size_text.dart";
import "package:flow/data/flow_report.dart";
import "package:flow/prefs.dart";
import "package:flow/routes/home/stats_tab/info_card_with_delta.dart";
import "package:flow/theme/theme.dart";
import "package:flow/widgets/general/frame.dart";
import "package:flow/widgets/general/money_text.dart";
import "package:flow/widgets/general/spinner.dart";
import "package:flow/widgets/home/home/info_card.dart";
import "package:flow/widgets/home/stats/range_daily_chart.dart";
import "package:flow/widgets/time_range_selector.dart";
import "package:flutter/material.dart";
Expand All @@ -25,6 +26,9 @@ class _StatsTabState extends State<StatsTab>

final AutoSizeGroup autoSizeGroup = AutoSizeGroup();

late final bool initiallyAbbreviated =
!LocalPreferences().preferFullAmounts.get();

bool busy = false;

@override
Expand Down Expand Up @@ -75,63 +79,71 @@ class _StatsTabState extends State<StatsTab>
],
),
),
const SizedBox(height: 96.0),
Frame(
child: Row(
children: [
Expanded(
child: InfoCard(
title: "Avg. daily expense",
moneyText: MoneyText(
report!.dailyAvgExpenditure,
tapToToggleAbbreviation: true,
autoSizeGroup: autoSizeGroup,
),
),
),
const SizedBox(width: 16.0),
Expanded(
child: InfoCard(
title: "Avg. daily income",
moneyText: MoneyText(
report!.dailyAvgIncome,
tapToToggleAbbreviation: true,
autoSizeGroup: autoSizeGroup,
),
),
),
],
),
),
const SizedBox(height: 16.0),
Frame(
child: Row(
const SizedBox(height: 24.0),
DefaultTextStyle(
style: context.textTheme.displaySmall!,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: InfoCard(
title:
"Forecast for ${report!.current.format()}",
moneyText: MoneyText(
report!.currentExpenseSumForecast,
tapToToggleAbbreviation: true,
autoSizeGroup: autoSizeGroup,
),
Frame(
child: Row(
children: [
Expanded(
child: InfoCardWithDelta(
title: "Avg. daily expense",
autoSizeGroup: autoSizeGroup,
money: report!.dailyAvgExpenditure,
previousMoney:
report!.previousDailyAvgExpenditure,
invertDelta: true,
),
),
const SizedBox(width: 16.0),
Expanded(
child: InfoCardWithDelta(
title: "Avg. daily income",
autoSizeGroup: autoSizeGroup,
money: report!.dailyAvgIncome,
previousMoney:
report!.previousDailyAvgIncome,
),
),
],
),
),
const SizedBox(width: 16.0),
Expanded(
child: InfoCard(
title: "Avg. daily flow",
moneyText: MoneyText(
report!.dailyAvgFlow,
tapToToggleAbbreviation: true,
autoSizeGroup: autoSizeGroup,
),
const SizedBox(height: 16.0),
Frame(
child: Row(
children: [
if (report!.currentExpenseSumForecast != null)
Expanded(
child: InfoCardWithDelta(
title:
"Forecast for ${report!.current.format()}",
autoSizeGroup: autoSizeGroup,
money:
report!.currentExpenseSumForecast!,
previousMoney:
report!.previousExpenseSum,
),
),
const SizedBox(width: 16.0),
Expanded(
child: InfoCardWithDelta(
title: "Avg. daily flow",
autoSizeGroup: autoSizeGroup,
money: report!.dailyAvgFlow,
previousMoney:
report!.previousDailyAvgFlow,
),
),
],
),
),
],
),
),
const SizedBox(height: 96.0),
],
),
)
Expand Down
78 changes: 78 additions & 0 deletions lib/routes/home/stats_tab/info_card_with_delta.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import "package:auto_size_text/auto_size_text.dart";
import "package:flow/data/money.dart";
import "package:flow/prefs.dart";
import "package:flow/theme/theme.dart";
import "package:flow/widgets/general/money_text.dart";
import "package:flow/widgets/home/home/info_card.dart";
import "package:flutter/material.dart";
import "package:material_symbols_icons/symbols.dart";

class InfoCardWithDelta extends StatelessWidget {
final Money money;
final Money? previousMoney;

final bool invertDelta;

final AutoSizeGroup? autoSizeGroup;

final String title;

const InfoCardWithDelta({
super.key,
required this.money,
required this.previousMoney,
required this.autoSizeGroup,
required this.title,
this.invertDelta = false,
});

@override
Widget build(BuildContext context) {
final double hundredPercent = previousMoney?.amount ?? 0;
final double delta = (hundredPercent == 0 ||
hundredPercent.isNaN ||
hundredPercent.isInfinite)
? 0
: (money.amount - hundredPercent) / hundredPercent;

final String deltaString = "${(delta.abs() * 100).toStringAsFixed(1)}%";

final bool downtrend = invertDelta ^ delta.isNegative;

final Color color =
downtrend ? context.flowColors.expense : context.flowColors.income;

return InfoCard(
title: title,
moneyText: MoneyText(
money,
tapToToggleAbbreviation: true,
initiallyAbbreviated: !LocalPreferences().preferFullAmounts.get(),
autoSize: true,
autoSizeGroup: autoSizeGroup,
style: context.textTheme.displaySmall,
),
delta: delta != 0.0
? Row(
mainAxisSize: MainAxisSize.min,
spacing: 4.0,
children: [
Icon(
delta.isNegative
? Symbols.arrow_downward
: Symbols.arrow_upward,
size: context.textTheme.titleSmall!.fontSize,
color: color,
),
Text(
deltaString,
style: context.textTheme.titleSmall!.copyWith(
color: color,
),
)
],
)
: null,
);
}
}
5 changes: 4 additions & 1 deletion lib/widgets/home/home/info_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class InfoCard extends StatelessWidget {
final String title;

final Widget? moneyText;
final Widget? delta;

final Widget? icon;

Expand All @@ -14,6 +15,7 @@ class InfoCard extends StatelessWidget {
required this.title,
this.icon,
this.moneyText,
this.delta,
});

@override
Expand Down Expand Up @@ -44,7 +46,8 @@ class InfoCard extends StatelessWidget {
],
],
),
if (moneyText != null) moneyText!
if (moneyText != null) moneyText!,
if (delta != null) delta!
],
),
),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: A personal finance managing app

publish_to: "none" # Remove this line if you wish to publish to pub.dev

version: "0.11.0+103"
version: "0.11.0+104"

environment:
sdk: ">=3.5.0 <4.0.0"
Expand Down
Loading