getting graph data from api
not sure if this is needed, was suggested though
This commit is contained in:
parent
4ab078c45e
commit
bf1046c4e5
4 changed files with 58 additions and 4 deletions
|
@ -6,13 +6,13 @@ PODS:
|
||||||
- Flutter
|
- Flutter
|
||||||
|
|
||||||
DEPENDENCIES:
|
DEPENDENCIES:
|
||||||
- Flutter (from `.symlinks/flutter/ios-profile`)
|
- Flutter (from `.symlinks/flutter/ios`)
|
||||||
- shared_preferences (from `.symlinks/plugins/shared_preferences/ios`)
|
- shared_preferences (from `.symlinks/plugins/shared_preferences/ios`)
|
||||||
- url_launcher (from `.symlinks/plugins/url_launcher/ios`)
|
- url_launcher (from `.symlinks/plugins/url_launcher/ios`)
|
||||||
|
|
||||||
EXTERNAL SOURCES:
|
EXTERNAL SOURCES:
|
||||||
Flutter:
|
Flutter:
|
||||||
:path: ".symlinks/flutter/ios-profile"
|
:path: ".symlinks/flutter/ios"
|
||||||
shared_preferences:
|
shared_preferences:
|
||||||
:path: ".symlinks/plugins/shared_preferences/ios"
|
:path: ".symlinks/plugins/shared_preferences/ios"
|
||||||
url_launcher:
|
url_launcher:
|
||||||
|
|
|
@ -281,7 +281,7 @@
|
||||||
);
|
);
|
||||||
inputPaths = (
|
inputPaths = (
|
||||||
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
|
"${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";
|
name = "[CP] Embed Pods Frameworks";
|
||||||
outputPaths = (
|
outputPaths = (
|
||||||
|
|
49
lib/common/apifunctions/get_graph_data.dart
Normal file
49
lib/common/apifunctions/get_graph_data.dart
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@ import 'package:local_spend/pages/spash_screen.dart';
|
||||||
import 'package:local_spend/pages/more_page.dart';
|
import 'package:local_spend/pages/more_page.dart';
|
||||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||||
|
|
||||||
|
import 'package:local_spend/common/apifunctions/get_graph_data.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(MyApp());
|
runApp(MyApp());
|
||||||
}
|
}
|
||||||
|
@ -13,9 +15,12 @@ void main() {
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
GraphData gd = new GraphData();
|
||||||
|
gd.getGraphData('total_last_week');
|
||||||
|
|
||||||
//var config = ConfigWrapper.of(context);
|
//var config = ConfigWrapper.of(context);
|
||||||
return new MaterialApp(
|
return new MaterialApp(
|
||||||
|
debugShowCheckedModeBanner: false,
|
||||||
localizationsDelegates: [
|
localizationsDelegates: [
|
||||||
GlobalMaterialLocalizations.delegate,
|
GlobalMaterialLocalizations.delegate,
|
||||||
GlobalWidgetsLocalizations.delegate,
|
GlobalWidgetsLocalizations.delegate,
|
||||||
|
|
Reference in a new issue