The initial page load now delays properly and shows the correct value rather than 0. Updating an item and going back to the page still shows old data though.
This commit is contained in:
parent
75cc72678b
commit
6f9d0d8afb
@ -1,4 +1,6 @@
|
|||||||
// Flutter
|
// Flutter
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import '/models/item_type.dart';
|
import '/models/item_type.dart';
|
||||||
|
|
||||||
@ -13,11 +15,11 @@ import '/models/tracked_item.dart';
|
|||||||
/// - Fix bug where editing an item does not reflect immediately when returning to Reports page.
|
/// - Fix bug where editing an item does not reflect immediately when returning to Reports page.
|
||||||
/// - Currently reflects after going back to Reports the 2nd time.
|
/// - Currently reflects after going back to Reports the 2nd time.
|
||||||
|
|
||||||
double _assetTotal = 0,
|
double _assetTotal = -1,
|
||||||
_expenseMonthly = 0,
|
_expenseMonthly = -1,
|
||||||
_expenseYearly = 0,
|
_expenseYearly = -1,
|
||||||
_incomeMonthly = 0,
|
_incomeMonthly = -1,
|
||||||
_incomeYearly = 0;
|
_incomeYearly = -1;
|
||||||
|
|
||||||
class ProjectionPage extends StatefulWidget {
|
class ProjectionPage extends StatefulWidget {
|
||||||
const ProjectionPage({
|
const ProjectionPage({
|
||||||
@ -29,6 +31,8 @@ class ProjectionPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _ProjectionPageState extends State<ProjectionPage> {
|
class _ProjectionPageState extends State<ProjectionPage> {
|
||||||
|
bool? _showProjections = true;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// Summaries for display as well as calculation of totals for projections.
|
// Summaries for display as well as calculation of totals for projections.
|
||||||
@ -46,50 +50,79 @@ class _ProjectionPageState extends State<ProjectionPage> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Calculations for the projections.
|
// Calculations for the projections.
|
||||||
double oneMonth = _assetTotal + _incomeMonthly - _expenseMonthly,
|
|
||||||
threeMonths = _assetTotal + (3 * (_incomeMonthly - _expenseMonthly)),
|
|
||||||
sixMonths = _assetTotal + (6 * (_incomeMonthly - _expenseMonthly)),
|
|
||||||
oneYear = _assetTotal + (_incomeYearly - _expenseYearly),
|
|
||||||
twoYears = _assetTotal + (2 * (_incomeYearly - _expenseYearly)),
|
|
||||||
fiveYears = _assetTotal + (5 * (_incomeYearly - _expenseYearly));
|
|
||||||
|
|
||||||
// Widgets to show the projections.
|
Widget projections;
|
||||||
Widget proj1 = SummaryCard(
|
if (_assetTotal < 0 ||
|
||||||
name: "One month from now...",
|
_incomeMonthly < 0 ||
|
||||||
leftText: "",
|
_incomeYearly < 0 ||
|
||||||
middleText: oneMonth.toStringAsFixed(2),
|
_expenseMonthly < 0 ||
|
||||||
rightText: "",
|
_expenseYearly < 0) {
|
||||||
);
|
_showProjections = false;
|
||||||
Widget proj2 = SummaryCard(
|
|
||||||
name: "Three months from now...",
|
projections = Center(child: SizedBox(child: CircularProgressIndicator()));
|
||||||
leftText: "",
|
|
||||||
middleText: threeMonths.toStringAsFixed(2),
|
Future.delayed(Duration(seconds: 1), () {
|
||||||
rightText: "",
|
setState(() {
|
||||||
);
|
_showProjections = true;
|
||||||
Widget proj3 = SummaryCard(
|
});
|
||||||
name: "Half a year from now...",
|
});
|
||||||
leftText: "",
|
} else {
|
||||||
middleText: sixMonths.toStringAsFixed(2),
|
double oneMonth = _assetTotal + _incomeMonthly - _expenseMonthly,
|
||||||
rightText: "",
|
threeMonths = _assetTotal + (3 * (_incomeMonthly - _expenseMonthly)),
|
||||||
);
|
sixMonths = _assetTotal + (6 * (_incomeMonthly - _expenseMonthly)),
|
||||||
Widget proj4 = SummaryCard(
|
oneYear = _assetTotal + (_incomeYearly - _expenseYearly),
|
||||||
name: "One year from now...",
|
twoYears = _assetTotal + (2 * (_incomeYearly - _expenseYearly)),
|
||||||
leftText: "",
|
fiveYears = _assetTotal + (5 * (_incomeYearly - _expenseYearly));
|
||||||
middleText: oneYear.toStringAsFixed(2),
|
|
||||||
rightText: "",
|
// Widgets to show the projections.
|
||||||
);
|
Widget proj1 = SummaryCard(
|
||||||
Widget proj5 = SummaryCard(
|
name: "One month from now...",
|
||||||
name: "Two years from now...",
|
leftText: "",
|
||||||
leftText: "",
|
middleText: oneMonth.toStringAsFixed(2),
|
||||||
middleText: twoYears.toStringAsFixed(2),
|
rightText: "",
|
||||||
rightText: "",
|
);
|
||||||
);
|
Widget proj2 = SummaryCard(
|
||||||
Widget proj6 = SummaryCard(
|
name: "Three months from now...",
|
||||||
name: "Five years from now...",
|
leftText: "",
|
||||||
leftText: "",
|
middleText: threeMonths.toStringAsFixed(2),
|
||||||
middleText: fiveYears.toStringAsFixed(2),
|
rightText: "",
|
||||||
rightText: "",
|
);
|
||||||
);
|
Widget proj3 = SummaryCard(
|
||||||
|
name: "Half a year from now...",
|
||||||
|
leftText: "",
|
||||||
|
middleText: sixMonths.toStringAsFixed(2),
|
||||||
|
rightText: "",
|
||||||
|
);
|
||||||
|
Widget proj4 = SummaryCard(
|
||||||
|
name: "One year from now...",
|
||||||
|
leftText: "",
|
||||||
|
middleText: oneYear.toStringAsFixed(2),
|
||||||
|
rightText: "",
|
||||||
|
);
|
||||||
|
Widget proj5 = SummaryCard(
|
||||||
|
name: "Two years from now...",
|
||||||
|
leftText: "",
|
||||||
|
middleText: twoYears.toStringAsFixed(2),
|
||||||
|
rightText: "",
|
||||||
|
);
|
||||||
|
Widget proj6 = SummaryCard(
|
||||||
|
name: "Five years from now...",
|
||||||
|
leftText: "",
|
||||||
|
middleText: fiveYears.toStringAsFixed(2),
|
||||||
|
rightText: "",
|
||||||
|
);
|
||||||
|
|
||||||
|
projections = Column(
|
||||||
|
children: [
|
||||||
|
proj1,
|
||||||
|
proj2,
|
||||||
|
proj3,
|
||||||
|
proj4,
|
||||||
|
proj5,
|
||||||
|
proj6,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Return all of the UI elements.
|
// Return all of the UI elements.
|
||||||
return ListView(
|
return ListView(
|
||||||
@ -99,12 +132,7 @@ class _ProjectionPageState extends State<ProjectionPage> {
|
|||||||
incomeSummary,
|
incomeSummary,
|
||||||
assetSummary,
|
assetSummary,
|
||||||
TitleCard(title: "Projections"),
|
TitleCard(title: "Projections"),
|
||||||
proj1,
|
projections,
|
||||||
proj2,
|
|
||||||
proj3,
|
|
||||||
proj4,
|
|
||||||
proj5,
|
|
||||||
proj6,
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user