From d9abbbd0e70ca8fac1e124ff2f495d71df821c56 Mon Sep 17 00:00:00 2001 From: Felix Date: Thu, 18 Jul 2019 16:38:12 +0100 Subject: [PATCH] Graph objectification --- lib/common/apifunctions/get_graph_data.dart | 4 +-- lib/common/widgets/charts/chart_builder.dart | 19 +++++++++++ lib/pages/receipt_page.dart | 36 ++++++++++---------- lib/pages/stats_page.dart | 16 +++++---- 4 files changed, 48 insertions(+), 27 deletions(-) create mode 100644 lib/common/widgets/charts/chart_builder.dart diff --git a/lib/common/apifunctions/get_graph_data.dart b/lib/common/apifunctions/get_graph_data.dart index 7729701..71ae7d6 100644 --- a/lib/common/apifunctions/get_graph_data.dart +++ b/lib/common/apifunctions/get_graph_data.dart @@ -49,8 +49,8 @@ class GraphData { List timeSeriesSpendList = new List(); for (int i = 0; i < labels.length; i++) { - print(DateTime(labels[i])); - timeSeriesSpendList.add(new TimeSeriesSpend(data[i], DateTime(labels[i]))); + print(DateTime.parse(labels[i])); + timeSeriesSpendList.add(new TimeSeriesSpend(data[i], DateTime.parse(labels[i]))); } return [ diff --git a/lib/common/widgets/charts/chart_builder.dart b/lib/common/widgets/charts/chart_builder.dart new file mode 100644 index 0000000..eea35bb --- /dev/null +++ b/lib/common/widgets/charts/chart_builder.dart @@ -0,0 +1,19 @@ +import 'package:flutter/material.dart'; +import 'package:local_spend/common/widgets/charts/time_series_simple.dart'; + +class TimeSeries extends StatelessWidget { + + final String chartDataName; + + TimeSeries({ + this.chartDataName, + }); + + @override + Widget build(BuildContext context) { + return new Container( + padding: EdgeInsets.symmetric(horizontal: 7.5, vertical: 7.5), + child: SimpleTimeSeriesChart.withSampleData(), + ); + } +} \ No newline at end of file diff --git a/lib/pages/receipt_page.dart b/lib/pages/receipt_page.dart index 03f5476..1dd800a 100644 --- a/lib/pages/receipt_page.dart +++ b/lib/pages/receipt_page.dart @@ -28,7 +28,7 @@ class ReceiptPageState extends State { final TextEditingController _amountController = TextEditingController(); final TextEditingController _essentialController = TextEditingController(); final TextEditingController _recurringController = TextEditingController(); - final TextEditingController _categoryController = TextEditingController(); + final TextEditingController _categoryController = TextEditingController(); // TODO: fix this final TextEditingController _orgController = TextEditingController(); final OrganizationController _organizationController = OrganizationController(); List _categoryDropDownItems = List(); @@ -542,23 +542,23 @@ class ReceiptPageState extends State { ), ), -// Container( -// padding: const EdgeInsets.fromLTRB(29, 0, 0, 0), -// child: DropdownButton( -// value: _categoryController.text, -// onChanged: (String newValue) { -// setState(() { -// _categoryController.text = newValue; -// }); -// }, -// items: _categoryDropDownItems.map>((String value) { -// return DropdownMenuItem( -// value: value, -// child: Text(value), -// ); -// }).toList(), // fix errors here by [items] being an empty container while _categoryDropDownItems is null -// ) -// ), + Container( + padding: const EdgeInsets.fromLTRB(29, 0, 0, 0), + child: DropdownButton( + value: _categoryController.text, + onChanged: (String newValue) { + setState(() { + _categoryController.text = newValue; + }); + }, + items: _categoryDropDownItems.map>((String value) { + return DropdownMenuItem( + value: value, + child: Text(value), + ); + }).toList(), // fix errors here by [items] being an empty container while _categoryDropDownItems is null + ) + ), ], ), diff --git a/lib/pages/stats_page.dart b/lib/pages/stats_page.dart index 157507f..c5be96b 100644 --- a/lib/pages/stats_page.dart +++ b/lib/pages/stats_page.dart @@ -15,6 +15,7 @@ import 'package:local_spend/common/widgets/charts/series_legend_with_measures.da 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; +import 'package:local_spend/common/widgets/charts/chart_builder.dart'; const URL = "https://flutter.io/"; const demonstration = false; @@ -50,12 +51,12 @@ class StatsPageState extends State { @override Widget build(BuildContext context) { // if (graphData.data != null) { - graphData.getGraphData('total_last_week').then((val) { - totalLastWeek = val; - setState(() { - // update view - }); - }); +// graphData.getGraphData('total_last_week').then((val) { +// totalLastWeek = val; +// setState(() { +// // update view +// }); +// }); // } return PlatformScaffold( @@ -97,7 +98,8 @@ class StatsPageState extends State { height: 200, // width: 250, - child: new SimpleTimeSeriesChart(totalLastWeek),//seriesList: List + child: new TimeSeries(), +// child: new SimpleTimeSeriesChart(totalLastWeek),//seriesList: List ), ],