Maps, optimization, testing, code cleanup

This commit is contained in:
Felix 2019-09-02 12:57:14 +01:00
parent c6e69b037b
commit a512549778
29 changed files with 257 additions and 176 deletions

View file

@ -4,14 +4,12 @@ import 'package:http/http.dart' as http;
import 'package:shared_preferences/shared_preferences.dart';
import 'package:charts_flutter/flutter.dart' as charts;
/// Customer graph types: https://dev.localspend.co.uk/api/v1/customer/graphs
/// - total_last_week
/// - avg_spend_last_week
/// - total_last_month
/// - avg_spend_last_month
/// Organisations' graphs types: to fetch, POST to https://dev.localspend.co.uk/api/stats/[name] as {"session_key":"[boop beep]"}
/// - organisations_all : organisation
/// - pies : organisation/pies
@ -28,16 +26,13 @@ import 'package:charts_flutter/flutter.dart' as charts;
/// HTTP POST request sample:
/// {"graph":"total_last_week","session_key":"blahblahblah"}
class OrganisationGraph {
OrganisationGraph(
this.chartType,
{this.graphsType = ""}
);
OrganisationGraph(this.chartType, {this.graphsType = ""});
String graphsType = ""; // type of graph, eg customers_last_7_days, sales_last_30_days, purchases_last_30_days etc
String chartType; // type of chart, eg organisations_all, pies, snippets or graphs
String graphsType =
""; // type of graph, eg customers_last_7_days, sales_last_30_days, purchases_last_30_days etc
String
chartType; // type of chart, eg organisations_all, pies, snippets or graphs
List<charts.Series<TimeSeriesCustomersOrSales, DateTime>> graph;
@ -53,7 +48,7 @@ class OrganisationGraph {
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
domainFn: (TimeSeriesCustomersOrSales spend, _) => spend.time,
measureFn: (TimeSeriesCustomersOrSales spend, _) =>
spend.numberOfStuff,
spend.numberOfStuff,
data: cachedData,
)
];
@ -94,13 +89,12 @@ class OrganisationGraph {
final List<dynamic> labels = responseJson['graph']['labels'];
final List<dynamic> data = responseJson['graph']['data'];
List<TimeSeriesCustomersOrSales> graphDataList = new List<
TimeSeriesCustomersOrSales>();
List<TimeSeriesCustomersOrSales> graphDataList =
new List<TimeSeriesCustomersOrSales>();
for (int i = 0; i < labels.length; i++) {
graphDataList.add(
new TimeSeriesCustomersOrSales(
data[i] * 1.00, DateTime.parse(labels[i])));
graphDataList.add(new TimeSeriesCustomersOrSales(
data[i] * 1.00, DateTime.parse(labels[i])));
}
this.cachedData = graphDataList;
@ -112,7 +106,7 @@ class OrganisationGraph {
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
domainFn: (TimeSeriesCustomersOrSales spend, _) => spend.time,
measureFn: (TimeSeriesCustomersOrSales spend, _) =>
spend.numberOfStuff,
spend.numberOfStuff,
data: graphDataList,
)
];
@ -125,9 +119,7 @@ class OrganisationGraph {
} catch (error) {
print(error.toString());
}
}
}
class GraphData {
@ -194,7 +186,6 @@ class GraphData {
)
];
return this.graph;
} else {
final errorMessage = json.decode(response.body)['message'];
print("Error: " + errorMessage);
@ -276,4 +267,4 @@ class TimeSeriesCustomersOrSales {
final DateTime time;
final double numberOfStuff;
}
}

View file

@ -0,0 +1,92 @@
import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;
import 'package:json_annotation/json_annotation.dart';
import 'package:local_spend/common/apifunctions/find_organisations.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart' as gmaps;
// /v1/supplier/location
@JsonSerializable()
class LatLng {
LatLng({
this.lat,
this.lng
});
final double lat, lng;
}
@JsonSerializable()
class Region {
Region({
this.coords,
this.id,
this.name,
this.zoom
});
final LatLng coords;
final String id, name;
final double zoom;
}
@JsonSerializable()
class Location {
Location({
this.organisation,
this.lat,
this.lng
});
final Organisation organisation;
final double lat, lng;
}
@JsonSerializable()
class Locations {
Locations({
this.locations,
this.regions
});
final List<Location> locations;
final List<Region> regions;
}
Future<Locations> getLocations(gmaps.LatLng ne, gmaps.LatLng sw) async {
const pearLocationsURL = 'https://dev.localspend.co.uk/api/v1/supplier/location';
SharedPreferences preferences = await SharedPreferences.getInstance();
Map<String, String> body;
body = {
'session_key': preferences.get('LastToken'),
};
Map<String, Map<String, double>> mapData = {
'north_east': {
'latitude': ne.latitude,
'longitude': ne.longitude
},
'south_west': {
'latitude': sw.latitude,
'longitude': sw.longitude
},
};
final response = await http.post(
pearLocationsURL,
body: json.encode(body),
);
if (response.statusCode == 200) {
print(response.body.toString());
} else {
print(response.body.toString());
throw HttpException(
'Error - ' + response.reasonPhrase,
);
}
}

View file

@ -264,10 +264,7 @@ class AboutDialog extends StatelessWidget {
List<Widget> body = <Widget>[];
if (icon != null) {
body.add(
IconTheme(
data: const IconThemeData(size: 45.0),
child: icon
),
IconTheme(data: const IconThemeData(size: 45.0), child: icon),
);
}
@ -277,7 +274,6 @@ class AboutDialog extends StatelessWidget {
child: ListBody(
children: <Widget>[
Container(
padding: EdgeInsets.only(top: 10),
child: Text(name, style: Theme.of(context).textTheme.title),
),
Text(version, style: Theme.of(context).textTheme.body1),

View file

@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:local_spend/common/apifunctions/request_logout_api.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:local_spend/common/functions/save_logout.dart';
void logout(context) {
_clearLoginDetails().then((_) {

View file

@ -4,21 +4,20 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class PlatformScaffold extends StatelessWidget {
PlatformScaffold(
{this.key,
this.appBar,
this.body,
this.floatingActionButton,
this.floatingActionButtonLocation,
this.floatingActionButtonAnimator,
this.persistentFooterButtons,
this.drawer,
this.endDrawer,
this.bottomNavigationBar,
this.backgroundColor,
this.resizeToAvoidBottomPadding = true,
this.primary = true})
this.appBar,
this.body,
this.floatingActionButton,
this.floatingActionButtonLocation,
this.floatingActionButtonAnimator,
this.persistentFooterButtons,
this.drawer,
this.endDrawer,
this.bottomNavigationBar,
this.backgroundColor,
this.resizeToAvoidBottomPadding = true,
this.primary = true})
: assert(primary != null),
super(key: key);

View file

@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:simple_animations/simple_animations.dart';
class AnimatedBackground extends StatelessWidget {
AnimatedBackground(
this.animateColors,
this.lastColor,

View file

@ -4,7 +4,6 @@ import 'package:charts_flutter/flutter.dart' as charts;
import 'package:flutter/material.dart';
class NumericComboLineBarChart extends StatelessWidget {
NumericComboLineBarChart(this.seriesList, {this.animate});
/// Creates a [LineChart] with sample data and no transition.

View file

@ -8,7 +8,6 @@ import 'package:charts_flutter/flutter.dart' as charts;
import 'package:flutter/material.dart';
class BucketingAxisScatterPlotChart extends StatelessWidget {
BucketingAxisScatterPlotChart(this.seriesList, {this.animate});
/// Creates a [ScatterPlotChart] with sample data and no transition.

View file

@ -372,8 +372,7 @@ class _RenderCheckbox extends RenderToggleable {
final double tShrink = (t - 0.5) * 2.0;
if (_oldValue == null || value == null) {
_drawDash(canvas, origin, tShrink, paint);
}
else {
} else {
_drawCheck(canvas, origin, tShrink, paint);
}
}
@ -388,16 +387,14 @@ class _RenderCheckbox extends RenderToggleable {
final double tShrink = 1.0 - tNormalized * 2.0;
if (_oldValue == true) {
_drawCheck(canvas, origin, tShrink, paint);
}
else {
} else {
_drawDash(canvas, origin, tShrink, paint);
}
} else {
final double tExpand = (tNormalized - 0.5) * 2.0;
if (value == true) {
_drawCheck(canvas, origin, tExpand, paint);
}
else {
} else {
_drawDash(canvas, origin, tExpand, paint);
}
}