Skip to content

Commit

Permalink
Feature: Show used budget in relation to time in month
Browse files Browse the repository at this point in the history
Merge pull request #490 from dreautall/feature/485-budget-time-line
  • Loading branch information
dreautall authored Nov 23, 2024
2 parents f8c64b3 + dded625 commit 2fcb7c3
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 42 deletions.
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

0 comments on commit 2fcb7c3

Please sign in to comment.