Code is B-E-A-U-TIFUL! All complies to standards.
Complies to flutter/dart 'pedantic' coding standards (their name, not mine)
This commit is contained in:
parent
19021a9a09
commit
55310068ea
55 changed files with 915 additions and 785 deletions
|
@ -2,7 +2,6 @@ import 'dart:convert';
|
|||
import 'dart:async';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:local_spend/common/functions/get_token.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
Future<List<String>> getCategories() async {
|
||||
const url = "https://dev.localspend.co.uk/api/search/category";
|
||||
|
@ -13,10 +12,10 @@ Future<List<String>> getCategories() async {
|
|||
});
|
||||
|
||||
Map<String, String> body = {
|
||||
"session_key":token,
|
||||
"session_key": token,
|
||||
};
|
||||
|
||||
final response = await http.post (
|
||||
final response = await http.post(
|
||||
url,
|
||||
body: json.encode(body),
|
||||
);
|
||||
|
@ -36,9 +35,8 @@ Future<List<String>> getCategories() async {
|
|||
|
||||
// print(categoriesJSON['11']); // prints "Banana"
|
||||
|
||||
int i = 1; // starts on 1. that was annoying to debug!
|
||||
int i = 1; // starts on 1. that was annoying to debug!
|
||||
while (true) {
|
||||
|
||||
if (categoriesJSON[i.toString()] != null) {
|
||||
// print("Iteration " + i.toString());
|
||||
// print(categoriesJSON[i.toString()]);
|
||||
|
@ -61,10 +59,10 @@ Future<List<String>> getCategories() async {
|
|||
|
||||
// print(categories[10].name.toString()); // prints "Banana"
|
||||
|
||||
return categories; // categories is List<Category>
|
||||
return categories; // categories is List<Category>
|
||||
// Category is defined at the top^^
|
||||
} else {
|
||||
// not successful
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,39 +1,32 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:async';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:local_spend/common/functions/get_token.dart';
|
||||
|
||||
class Organisation {
|
||||
var id = 0;
|
||||
var name = "";
|
||||
var postcode = "";
|
||||
var streetName = ""; //street_name
|
||||
var town = "";
|
||||
|
||||
Organisation(
|
||||
this.id,
|
||||
this.name,
|
||||
this.postcode,
|
||||
this.streetName,
|
||||
this.town,
|
||||
);
|
||||
);
|
||||
|
||||
var id = 0;
|
||||
var name = "";
|
||||
var postcode = "";
|
||||
var streetName = ""; //street_name
|
||||
var town = "";
|
||||
}
|
||||
|
||||
class Organisations {
|
||||
|
||||
List<Organisation> getTestData() {
|
||||
var numItems = 10;
|
||||
var itemsList = new List<Organisation>();
|
||||
|
||||
for (int i = 0; i < numItems; i++) {
|
||||
itemsList.add(new Organisation(
|
||||
i,
|
||||
"Payee " + (i + 1).toString(),
|
||||
"tee hee hee",
|
||||
"yeet street",
|
||||
"Robloxia"
|
||||
));
|
||||
itemsList.add(new Organisation(i, "Payee " + (i + 1).toString(),
|
||||
"tee hee hee", "yeet street", "Robloxia"));
|
||||
}
|
||||
|
||||
return itemsList;
|
||||
|
@ -72,11 +65,11 @@ class Organisations {
|
|||
});
|
||||
|
||||
Map<String, String> body = {
|
||||
"search_name":search,
|
||||
"session_key":token,
|
||||
"search_name": search,
|
||||
"session_key": token,
|
||||
};
|
||||
|
||||
final response = await http.post (
|
||||
final response = await http.post(
|
||||
url,
|
||||
body: json.encode(body),
|
||||
);
|
||||
|
@ -88,6 +81,5 @@ class Organisations {
|
|||
// not successful
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,13 +5,13 @@ import 'package:shared_preferences/shared_preferences.dart';
|
|||
import 'package:charts_flutter/flutter.dart' as charts;
|
||||
|
||||
class GraphData {
|
||||
var chartType;
|
||||
List<charts.Series<dynamic, DateTime>> graph;
|
||||
|
||||
GraphData(
|
||||
this.chartType,
|
||||
);
|
||||
|
||||
var chartType;
|
||||
List<charts.Series<dynamic, DateTime>> graph;
|
||||
|
||||
List<TimeSeriesSpend> cachedData;
|
||||
bool loaded = false;
|
||||
|
||||
|
@ -49,7 +49,8 @@ class GraphData {
|
|||
List<TimeSeriesSpend> timeSeriesSpendList = new List<TimeSeriesSpend>();
|
||||
|
||||
for (int i = 0; i < labels.length; i++) {
|
||||
timeSeriesSpendList.add(new TimeSeriesSpend(data[i]*1.00, DateTime.parse(labels[i])));
|
||||
timeSeriesSpendList.add(
|
||||
new TimeSeriesSpend(data[i] * 1.00, DateTime.parse(labels[i])));
|
||||
// print(timeSeriesSpendList[i].time.toString() + " : " + timeSeriesSpendList[i].spend.toString());
|
||||
}
|
||||
|
||||
|
@ -131,7 +132,8 @@ class GraphData {
|
|||
List<TimeSeriesSpend> timeSeriesSpendList = new List<TimeSeriesSpend>();
|
||||
|
||||
for (int i = 0; i < labels.length; i++) {
|
||||
timeSeriesSpendList.add(new TimeSeriesSpend(data[i]*1.00, DateTime.parse(labels[i])));
|
||||
timeSeriesSpendList.add(
|
||||
new TimeSeriesSpend(data[i] * 1.00, DateTime.parse(labels[i])));
|
||||
// print(timeSeriesSpendList[i].time.toString() + " : " + timeSeriesSpendList[i].spend.toString());
|
||||
}
|
||||
|
||||
|
@ -154,18 +156,16 @@ class GraphData {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class OrgGraphData {
|
||||
var chartType;
|
||||
List<charts.Series<dynamic, DateTime>> graph;
|
||||
|
||||
OrgGraphData(
|
||||
this.chartType,
|
||||
);
|
||||
|
||||
var chartType;
|
||||
List<charts.Series<dynamic, DateTime>> graph;
|
||||
|
||||
List<TimeSeriesSpend> cachedData;
|
||||
bool loaded = false;
|
||||
|
||||
|
@ -203,7 +203,8 @@ class OrgGraphData {
|
|||
List<TimeSeriesSpend> timeSeriesSpendList = new List<TimeSeriesSpend>();
|
||||
|
||||
for (int i = 0; i < labels.length; i++) {
|
||||
timeSeriesSpendList.add(new TimeSeriesSpend(data[i]*1.00, DateTime.parse(labels[i])));
|
||||
timeSeriesSpendList.add(
|
||||
new TimeSeriesSpend(data[i] * 1.00, DateTime.parse(labels[i])));
|
||||
// print(timeSeriesSpendList[i].time.toString() + " : " + timeSeriesSpendList[i].spend.toString());
|
||||
}
|
||||
|
||||
|
@ -285,7 +286,8 @@ class OrgGraphData {
|
|||
List<TimeSeriesSpend> timeSeriesSpendList = new List<TimeSeriesSpend>();
|
||||
|
||||
for (int i = 0; i < labels.length; i++) {
|
||||
timeSeriesSpendList.add(new TimeSeriesSpend(data[i]*1.00, DateTime.parse(labels[i])));
|
||||
timeSeriesSpendList.add(
|
||||
new TimeSeriesSpend(data[i] * 1.00, DateTime.parse(labels[i])));
|
||||
// print(timeSeriesSpendList[i].time.toString() + " : " + timeSeriesSpendList[i].spend.toString());
|
||||
}
|
||||
|
||||
|
@ -308,14 +310,11 @@ class OrgGraphData {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class TimeSeriesSpend {
|
||||
TimeSeriesSpend(this.spend, this.time);
|
||||
|
||||
final DateTime time;
|
||||
final double spend;
|
||||
|
||||
TimeSeriesSpend(this.spend, this.time);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,9 +13,11 @@ Future<void> _incorrectDialog(BuildContext context, bool isLoginWrong) async {
|
|||
builder: (BuildContext context) {
|
||||
return AnimatedContainer(
|
||||
duration: Duration(seconds: 2),
|
||||
child : AlertDialog(
|
||||
child: AlertDialog(
|
||||
title: Text("Uh-oh!"),
|
||||
content: Text(isLoginWrong ? "Incorrect login details. Please try again." : "Our servers are having issues at the moment; sorry for the inconvenience. Please try again later."),
|
||||
content: Text(isLoginWrong
|
||||
? "Incorrect login details. Please try again."
|
||||
: "Our servers are having issues at the moment; sorry for the inconvenience. Please try again later."),
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
child: Text('OK'),
|
||||
|
@ -30,7 +32,8 @@ Future<void> _incorrectDialog(BuildContext context, bool isLoginWrong) async {
|
|||
);
|
||||
}
|
||||
|
||||
Future<LoginModel> requestLoginAPI(BuildContext context, String email, String password) async {
|
||||
Future<LoginModel> requestLoginAPI(
|
||||
BuildContext context, String email, String password) async {
|
||||
final url = "https://dev.localspend.co.uk/api/login";
|
||||
|
||||
Map<String, String> body = {
|
||||
|
@ -38,19 +41,19 @@ Future<LoginModel> requestLoginAPI(BuildContext context, String email, String pa
|
|||
'password': password,
|
||||
};
|
||||
|
||||
// debugPrint('$body');
|
||||
|
||||
try {
|
||||
final response = await http.post(
|
||||
url,
|
||||
body: json.encode(body),
|
||||
).timeout(Duration(seconds: 5));
|
||||
final response = await http
|
||||
.post(
|
||||
url,
|
||||
body: json.encode(body),
|
||||
)
|
||||
.timeout(Duration(seconds: 5));
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final responseJson = json.decode(response.body);
|
||||
|
||||
saveCurrentLogin(responseJson, body["email"]);
|
||||
Navigator.of(context).pushReplacementNamed('/HomePage');
|
||||
await Navigator.of(context).pushReplacementNamed('/HomePage');
|
||||
|
||||
return LoginModel.fromJson(responseJson);
|
||||
} else {
|
||||
|
@ -58,15 +61,15 @@ Future<LoginModel> requestLoginAPI(BuildContext context, String email, String pa
|
|||
|
||||
saveCurrentLogin(responseJson, body["email"]);
|
||||
|
||||
_incorrectDialog(context, true);
|
||||
await _incorrectDialog(context, true);
|
||||
|
||||
return null;
|
||||
}
|
||||
} on TimeoutException catch (_) {
|
||||
_incorrectDialog(context, false);
|
||||
await _incorrectDialog(context, false);
|
||||
} catch (error) {
|
||||
debugPrint(error.toString());
|
||||
_incorrectDialog(context, false);
|
||||
await _incorrectDialog(context, false);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ Future<LoginModel> requestLogoutAPI(BuildContext context) async {
|
|||
});
|
||||
|
||||
Map<String, String> body = {
|
||||
"Token":token,
|
||||
"Token": token,
|
||||
};
|
||||
|
||||
final response = await http.post(
|
||||
|
|
|
@ -28,7 +28,7 @@ Future<LoginModel> submitReceiptAPI(
|
|||
SharedPreferences preferences = await SharedPreferences.getInstance();
|
||||
|
||||
Map<String, String> body = {
|
||||
'transaction_type' : "3",
|
||||
'transaction_type': "3",
|
||||
'transaction_value': receipt.amount,
|
||||
'purchase_time': receipt.time,
|
||||
'category': receipt.category,
|
||||
|
@ -38,7 +38,6 @@ Future<LoginModel> submitReceiptAPI(
|
|||
'street_name': receipt.street,
|
||||
'postcode': receipt.postcode,
|
||||
'town': receipt.town,
|
||||
|
||||
'session_key': preferences.get('LastToken'),
|
||||
};
|
||||
|
||||
|
@ -61,13 +60,11 @@ Future<LoginModel> submitReceiptAPI(
|
|||
context,
|
||||
responseJson[0] == "" ? responseJson[0] : "Upload Successful",
|
||||
"Transaction successfully submitted to server",
|
||||
"OK"
|
||||
);
|
||||
"OK");
|
||||
return LoginModel.fromJson(responseJson);
|
||||
} else {
|
||||
final responseJson = json.decode(response.body);
|
||||
|
||||
|
||||
showDialogSingleButton(
|
||||
context,
|
||||
"Unable to Submit Receipt",
|
||||
|
|
Reference in a new issue