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

Feature: Show used budget in relation to time in month #490

Merged
merged 2 commits into from
Nov 23, 2024
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
104 changes: 67 additions & 37 deletions lib/pages/home/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,14 @@ class BudgetList extends StatelessWidget {
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
final List<Widget> widgets = <Widget>[];
final DateTime now = tzHandler
.sNow()
.setTimeOfDay(const TimeOfDay(hour: 12, minute: 0));
final DateTime lastDayInMonth =
tzHandler.sTime(now.copyWith(month: now.month + 1, day: 0));
final double passedDays = now.day / lastDayInMonth.day;
for (BudgetLimitRead budget in snapshot.data!) {
final List<Widget> stackWidgets = <Widget>[];
final double spent =
(double.tryParse(budget.attributes.spent ?? "0") ?? 0).abs();
final double available =
Expand Down Expand Up @@ -1099,40 +1106,38 @@ class BudgetList extends StatelessWidget {
if (widgets.isNotEmpty) {
widgets.add(const SizedBox(height: 8));
}
widgets.add(
RichText(
text: TextSpan(
children: <InlineSpan>[
TextSpan(
text: budgetInfo.name,
style: Theme.of(context).textTheme.titleSmall,
),
TextSpan(
text: budget.attributes.period?.isNotEmpty ?? false
? S.of(context).homeMainBudgetInterval(
tzHandler
.sTime(budget.attributes.start)
.toLocal(),
tzHandler
.sTime(budget.attributes.end)
.toLocal(),
budget.attributes.period!,
)
: S.of(context).homeMainBudgetIntervalSingle(
tzHandler
.sTime(budget.attributes.start)
.toLocal(),
tzHandler
.sTime(budget.attributes.end)
.toLocal(),
),
style: Theme.of(context).textTheme.bodyMedium,
),
],
),
widgets.add(RichText(
text: TextSpan(
children: <InlineSpan>[
TextSpan(
text: budgetInfo.name,
style: Theme.of(context).textTheme.titleSmall,
),
TextSpan(
text: budget.attributes.period?.isNotEmpty ?? false
? S.of(context).homeMainBudgetInterval(
tzHandler
.sTime(budget.attributes.start)
.toLocal(),
tzHandler
.sTime(budget.attributes.end)
.toLocal(),
budget.attributes.period!,
)
: S.of(context).homeMainBudgetIntervalSingle(
tzHandler
.sTime(budget.attributes.start)
.toLocal(),
tzHandler
.sTime(budget.attributes.end)
.toLocal(),
),
style: Theme.of(context).textTheme.bodyMedium,
),
],
),
);
widgets.add(Row(
));
stackWidgets.add(Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
Expand Down Expand Up @@ -1161,10 +1166,35 @@ class BudgetList extends StatelessWidget {
),
],
));
widgets.add(LinearProgressIndicator(
color: lineColor,
backgroundColor: bgColor,
value: value,
stackWidgets.add(Positioned.fill(
top: 20, // Height of Row() with text
bottom: 4,
child: LinearProgressIndicator(
color: lineColor,
backgroundColor: bgColor,
value: value,
),
));
widgets.add(LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) =>
Stack(
children: <Widget>[
// Row + ProgressIndicator + Bottom Padding
const SizedBox(height: 20 + 4 + 4),
...stackWidgets,
Positioned(
left: constraints.biggest.width * passedDays,
top: 16,
bottom: 0,
width: 3,
child: Container(
color: (spent / available > passedDays)
? Colors.redAccent
: Colors.blueAccent,
),
),
],
),
));
}
return Column(
Expand Down
10 changes: 5 additions & 5 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ dependencies:
dev_dependencies:
flutter_lints: ^5.0.0
# needed for swagger_dart_code_generator
build_runner: ^2.4.7
chopper_generator: ^8.0.2
json_serializable: ^6.7.1
swagger_dart_code_generator: ^3.0.0
flutter_native_splash: ^2.3.10
build_runner: ^2.4.13
chopper_generator: ^8.0.3
json_serializable: ^6.9.0
swagger_dart_code_generator: ^3.0.1
flutter_native_splash: ^2.4.3
translations_cleaner: ^0.0.5

flutter:
Expand Down
Loading