getting graph data from api

not sure if this is needed, was suggested though
This commit is contained in:
Felix 2019-07-18 10:26:37 +01:00
parent 4ab078c45e
commit bf1046c4e5
No known key found for this signature in database
GPG key ID: 130EF6DC43E4DD07
4 changed files with 58 additions and 4 deletions

View file

@ -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:

View file

@ -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 = (

View file

@ -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<DataPoint> data = new List<DataPoint>();
Future<List<DataPoint>> 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<String, String> 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);
}
}
}

View file

@ -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,