implementing API graphs and getting frustrated at async stuff

This commit is contained in:
Felix 2019-07-18 12:05:09 +01:00
parent bf1046c4e5
commit d7625f7b88
No known key found for this signature in database
GPG key ID: 130EF6DC43E4DD07
7 changed files with 134 additions and 169 deletions

View file

@ -204,7 +204,7 @@ class ReceiptPageState extends State<ReceiptPage> {
List<String> getRecurringOptions() {
var options = new List<String>(7);
options[0] = "None";
options[0] = "None"; // this should not be hardcoded and should be fetched from API instead
options[1] = "Daily";
options[2] = "Weekly";
options[3] = "Fortnightly";
@ -556,7 +556,7 @@ class ReceiptPageState extends State<ReceiptPage> {
value: value,
child: Text(value),
);
}).toList(),
}).toList(), // fix errors here by [items] being an empty container while _categoryDropDownItems is null
)
),
],

View file

@ -12,6 +12,9 @@ import 'package:local_spend/common/widgets/charts/grouped_bar_chart.dart';
import 'package:local_spend/common/widgets/charts/scatter_bucketingAxis_legend.dart';
import 'package:local_spend/common/widgets/charts/numeric_line_bar_combo.dart';
import 'package:local_spend/common/widgets/charts/series_legend_with_measures.dart';
import 'package:local_spend/common/widgets/charts/time_series_simple.dart';
import 'package:local_spend/common/apifunctions/get_graph_data.dart';
import 'package:charts_flutter/flutter.dart' as charts;
const URL = "https://flutter.io/";
const demonstration = false;
@ -25,6 +28,9 @@ class StatsPage extends StatefulWidget {
class StatsPageState extends State<StatsPage> {
GraphData graphData = new GraphData();
List<charts.Series> totalLastWeek;
@override
void initState() {
super.initState();
@ -43,6 +49,15 @@ class StatsPageState extends State<StatsPage> {
@override
Widget build(BuildContext context) {
if (graphData.data != null) {
graphData.getGraphData('total_last_week').then((val) {
totalLastWeek = val;
setState(() {
// update view
});
});
}
return PlatformScaffold(
appBar: AppBar(
backgroundColor: Colors.blue[400],
@ -63,30 +78,11 @@ class StatsPageState extends State<StatsPage> {
padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
child: ListView(
children: <Widget>[
// some graphs and charts here etc
// Container(
// padding: EdgeInsets.fromLTRB(0.0,17,0.0,0.0),
// child : Text(
// "Really Cool Chart",
// textAlign: TextAlign.center,
// style: TextStyle(
// fontSize: 22.0,
// color: Colors.black,
// fontWeight: FontWeight.bold,
// ),
// ),
// ),
//
// Container(
// height: 250,
//// width: 250,
// child: new DonutPieChart.withSampleData()
// ),
Container(
padding: EdgeInsets.fromLTRB(0.0,17,0.0,0.0),
child : Text(
"GroupedBarChart",
"This Week's Spend",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 22.0,
@ -100,127 +96,8 @@ class StatsPageState extends State<StatsPage> {
padding: EdgeInsets.symmetric(horizontal: 10),
height: 200,
// width: 250,
child: new GroupedBarChart.withSampleData()
),
Container(
padding: EdgeInsets.fromLTRB(0.0,17,0.0,0.0),
child : Text(
"BucketingAxisScatterPlotChart",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 22.0,
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
),
Container(
padding: EdgeInsets.symmetric(horizontal: 10),
height: 200,
// width: 250,
child: new BucketingAxisScatterPlotChart.withSampleData()
),
Container(
padding: EdgeInsets.fromLTRB(0.0,20,0.0,0.0),
child : Text(
"PieOutsideLabelChart",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 22.0,
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
),
Container(
padding: EdgeInsets.symmetric(horizontal: 10),
height: 200,
// width: 250,
child: new PieOutsideLabelChart.withSampleData()
),
Container(
padding: EdgeInsets.fromLTRB(0.0,17,0.0,0.0),
child : Text(
"DonutAutoLabelChart",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 22.0,
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
),
Container(
padding: EdgeInsets.symmetric(horizontal: 10),
height: 200,
// width: 250,
child: new DonutAutoLabelChart.withSampleData()
),
Container(
padding: EdgeInsets.fromLTRB(0.0,17,0.0,0.0),
child : Text(
"DonutPieChart",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 22.0,
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
),
Container(
padding: EdgeInsets.symmetric(horizontal: 10),
height: 200,
// width: 250,
child: new DonutPieChart.withSampleData()
),
Container(
padding: EdgeInsets.fromLTRB(0.0,17,0.0,0.0),
child : Text(
"NumericComboLineBarChart",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 22.0,
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
),
Container(
padding: EdgeInsets.symmetric(horizontal: 10),
height: 200,
// width: 250,
child: new NumericComboLineBarChart.withSampleData()
),
Container(
padding: EdgeInsets.fromLTRB(0.0,17,0.0,0.0),
child : Text(
"LegendWithMeasures",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 22.0,
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
),
Container(
padding: EdgeInsets.symmetric(horizontal: 10),
height: 200,
// width: 250,
child: new LegendWithMeasures.withSampleData()
child: new SimpleTimeSeriesChart(totalLastWeek),//seriesList: List<charts.Series>
),
],