From bf1046c4e5f2f68421040c50591bb29a4c7cecaf Mon Sep 17 00:00:00 2001 From: Felix Date: Thu, 18 Jul 2019 10:26:37 +0100 Subject: [PATCH] getting graph data from api not sure if this is needed, was suggested though --- ios/Podfile.lock | 4 +- ios/Runner.xcodeproj/project.pbxproj | 2 +- lib/common/apifunctions/get_graph_data.dart | 49 +++++++++++++++++++++ lib/main.dart | 7 ++- 4 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 lib/common/apifunctions/get_graph_data.dart diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 81f2036..f5bffe1 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -6,13 +6,13 @@ PODS: - Flutter DEPENDENCIES: - - Flutter (from `.symlinks/flutter/ios-profile`) + - Flutter (from `.symlinks/flutter/ios`) - shared_preferences (from `.symlinks/plugins/shared_preferences/ios`) - url_launcher (from `.symlinks/plugins/url_launcher/ios`) EXTERNAL SOURCES: Flutter: - :path: ".symlinks/flutter/ios-profile" + :path: ".symlinks/flutter/ios" shared_preferences: :path: ".symlinks/plugins/shared_preferences/ios" url_launcher: diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index dff0209..a83a4d3 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -281,7 +281,7 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", - "${PODS_ROOT}/../.symlinks/flutter/ios-profile/Flutter.framework", + "${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( diff --git a/lib/common/apifunctions/get_graph_data.dart b/lib/common/apifunctions/get_graph_data.dart new file mode 100644 index 0000000..e217901 --- /dev/null +++ b/lib/common/apifunctions/get_graph_data.dart @@ -0,0 +1,49 @@ +import 'dart:convert'; +import 'dart:async'; +import 'package:http/http.dart' as http; +import 'package:shared_preferences/shared_preferences.dart'; + +enum DataPoint {date, String} + +class GraphData { + List data = new List(); + + Future> getGraphData(String graphType) async { + /// Graph types: + /// - total_last_week + /// - avg_spend_last_week + /// - total_last_month + /// - avg_spend_last_month + /// + /// HTTP POST request sample: + /// {"graph":"total_last_week","session_key":"blahblahblah"} + + final url = "https://dev.peartrade.org/api/v1/customer/graphs"; + SharedPreferences preferences = await SharedPreferences.getInstance(); + + Map body = { + 'graph': graphType, + 'session_key': preferences.get('LastToken'), + }; + + final response = await http.post( + url, + body: json.encode(body), + ); + + if (response.statusCode == 200) { + final responseJson = jsonDecode(response.body); + final labels = responseJson['graph']['labels']; + final data = responseJson['graph']['data']; +// final bounds = responseJson['graph']['bounds']; // why is this even returned? +// print(labels[5]); +// print(data[5]); + } else { + final errorMessage = json.decode(response.body)['message']; + print("Error: " + errorMessage); + } + } + + +} + diff --git a/lib/main.dart b/lib/main.dart index a4a84be..7970364 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -6,6 +6,8 @@ import 'package:local_spend/pages/spash_screen.dart'; import 'package:local_spend/pages/more_page.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; +import 'package:local_spend/common/apifunctions/get_graph_data.dart'; + void main() { runApp(MyApp()); } @@ -13,9 +15,12 @@ void main() { class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { + GraphData gd = new GraphData(); + gd.getGraphData('total_last_week'); + //var config = ConfigWrapper.of(context); return new MaterialApp( - + debugShowCheckedModeBanner: false, localizationsDelegates: [ GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate,