optimized

This commit is contained in:
Mohamed Nouffer
2023-10-06 16:25:21 +05:30
parent 7fdb6c05ee
commit 0e2a8f89f3
101 changed files with 50948 additions and 4137 deletions

View File

@ -6,8 +6,7 @@ import 'package:http/http.dart' as http;
import 'package:rogapp/pages/index/index_controller.dart';
import 'package:rogapp/utils/const.dart';
class LocationService{
class LocationService {
// static Future<GeoJsonFeatureCollection?> loadLocations() async {
// final IndexController indexController = Get.find<IndexController>();
@ -34,42 +33,42 @@ class LocationService{
// return null;
// }
static Future<GeoJsonFeatureCollection?> loadLocationsFor(String perfecture, String cat) async {
static Future<GeoJsonFeatureCollection?> loadLocationsFor(
String perfecture, String cat) async {
final IndexController indexController = Get.find<IndexController>();
String url = "";
String serverUrl = ConstValues.currentServer();
if(cat.isNotEmpty){
if(indexController.currentUser.isNotEmpty){
bool _rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = _rog == true ? 'True': 'False';
if (cat.isNotEmpty) {
if (indexController.currentUser.isNotEmpty) {
bool rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = rog == true ? 'True' : 'False';
var grp = indexController.currentUser[0]['user']['event_code'];
url = '$serverUrl/api/inperf/?rog=$r&perf=' + perfecture + '&cat=' + cat;
url = '$serverUrl/api/inperf/?rog=$r&perf=$perfecture&cat=$cat';
} else {
url = '$serverUrl/api/inperf/?perf=$perfecture&cat=$cat';
}
else {
url = '$serverUrl/api/inperf/?perf=' + perfecture + '&cat=' + cat;
} else {
if (indexController.currentUser.isNotEmpty) {
bool rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = rog == true ? 'True' : 'False';
var grp = indexController.currentUser[0]['user']['event_code'];
url = '$serverUrl/api/inperf/?rog=$r&perf=$perfecture';
} else {
url = '$serverUrl/api/inperf/?perf=$perfecture';
}
}
else{
if(indexController.currentUser.isNotEmpty){
bool _rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = _rog == true ? 'True': 'False';
var grp = indexController.currentUser[0]['user']['event_code'];
url = '$serverUrl/api/inperf/?rog=$r&perf=' + perfecture;
}
else {
url = '$serverUrl/api/inperf/?perf=' + perfecture;
}
}
print('++++++++$url');
final response = await http.get(Uri.parse(url),
//print('++++++++$url');
final response = await http.get(
Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
);
if (response.statusCode == 200) {
GeoJsonFeatureCollection cc = await featuresFromGeoJson(utf8.decode(response.bodyBytes));
GeoJsonFeatureCollection cc =
await featuresFromGeoJson(utf8.decode(response.bodyBytes));
//print(cc);
return cc; //featuresFromGeoJson(utf8.decode(response.bodyBytes));
}
@ -80,97 +79,104 @@ class LocationService{
List<dynamic> ext = [];
String serverUrl = ConstValues.currentServer();
String url = '$serverUrl/api/locsext/';
print('++++++++$url');
//print('++++++++$url');
final response = await http.post(Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'Token $token'
},
body: jsonEncode(<String, String>{
'token': token,
})
);
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'Token $token'
},
body: jsonEncode(<String, String>{
'token': token,
}));
if (response.statusCode == 200) {
ext = json.decode(utf8.decode(response.bodyBytes));
}
return ext;
}
static Future<GeoJsonFeatureCollection?> loadLocationsSubFor(String subperfecture, String cat) async {
static Future<GeoJsonFeatureCollection?> loadLocationsSubFor(
String subperfecture, String cat) async {
final IndexController indexController = Get.find<IndexController>();
String url = "";
String serverUrl = ConstValues.currentServer();
if(cat.isNotEmpty){
if(indexController.currentUser.isNotEmpty){
bool _rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = _rog == true ? 'True': 'False';
if (cat.isNotEmpty) {
if (indexController.currentUser.isNotEmpty) {
bool rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = rog == true ? 'True' : 'False';
var grp = indexController.currentUser[0]['user']['event_code'];
url = '$serverUrl/api/insubperf?rog=$r&subperf=' + subperfecture + '&cat=' + cat;
url = '$serverUrl/api/insubperf?rog=$r&subperf=$subperfecture&cat=$cat';
} else {
url = '$serverUrl/api/insubperf?subperf=$subperfecture&cat=$cat';
}
else{
url = '$serverUrl/api/insubperf?subperf=' + subperfecture + '&cat=' + cat;
} else {
if (indexController.currentUser.isNotEmpty) {
bool rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = rog == true ? 'True' : 'False';
var grp = indexController.currentUser[0]['user']['event_code'];
url = '$serverUrl/api/insubperf?rog=$r&subperf=$subperfecture';
} else {
url = '$serverUrl/api/insubperf?subperf=$subperfecture';
}
}
else{
if(indexController.currentUser.isNotEmpty){
bool _rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = _rog == true ? 'True': 'False';
var grp = indexController.currentUser[0]['user']['event_code'];
url = '$serverUrl/api/insubperf?rog=$r&subperf=' + subperfecture;
}
else{
url = '$serverUrl/api/insubperf?subperf=' + subperfecture;
}
}
print('++++++++$url');
final response = await http.get(Uri.parse(url),
//print('++++++++$url');
final response = await http.get(
Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
);
if (response.statusCode == 200) {
GeoJsonFeatureCollection cc = await featuresFromGeoJson(utf8.decode(response.bodyBytes));
GeoJsonFeatureCollection cc =
await featuresFromGeoJson(utf8.decode(response.bodyBytes));
//print(cc);
return cc; //featuresFromGeoJson(utf8.decode(response.bodyBytes));
}
return null;
}
static Future<GeoJsonFeatureCollection?> loadLocationsBound(double lat1, double lon1, double lat2, double lon2, double lat3, double lon3, double lat4, double lon4, String cat) async {
print("-------- in location for bound -------------");
static Future<GeoJsonFeatureCollection?> loadLocationsBound(
double lat1,
double lon1,
double lat2,
double lon2,
double lat3,
double lon3,
double lat4,
double lon4,
String cat) async {
//print("-------- in location for bound -------------");
final IndexController indexController = Get.find<IndexController>();
String url = "";
String serverUrl = ConstValues.currentServer();
if(cat.isNotEmpty){
if(indexController.currentUser.isNotEmpty){
bool _rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = _rog == true ? 'True': 'False';
if (cat.isNotEmpty) {
if (indexController.currentUser.isNotEmpty) {
bool rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = rog == true ? 'True' : 'False';
var grp = indexController.currentUser[0]['user']['event_code'];
url = '$serverUrl/api/inbound?rog=$r&grp=$grp&ln1=$lon1&la1=$lat1&ln2=$lon2&la2=$lat2&ln3=$lon3&la3=$lat3&ln4=$lon4&la4=$lat4' '&cat=' + cat;
url =
'$serverUrl/api/inbound?rog=$r&grp=$grp&ln1=$lon1&la1=$lat1&ln2=$lon2&la2=$lat2&ln3=$lon3&la3=$lat3&ln4=$lon4&la4=$lat4&cat=$cat';
} else {
url =
'$serverUrl/api/inbound?ln1=$lon1&la1=$lat1&ln2=$lon2&la2=$lat2&ln3=$lon3&la3=$lat3&ln4=$lon4&la4=$lat4&cat=$cat';
}
else{
url = '$serverUrl/api/inbound?ln1=$lon1&la1=$lat1&ln2=$lon2&la2=$lat2&ln3=$lon3&la3=$lat3&ln4=$lon4&la4=$lat4' '&cat=' + cat;
} else {
if (indexController.currentUser.isNotEmpty) {
bool rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = rog == true ? 'True' : 'False';
var grp = indexController.currentUser[0]['user']['event_code'];
//print("-------- requested user group $grp -------------");
url =
'$serverUrl/api/inbound?rog=$r&grp=$grp&ln1=$lon1&la1=$lat1&ln2=$lon2&la2=$lat2&ln3=$lon3&la3=$lat3&ln4=$lon4&la4=$lat4';
} else {
url =
'$serverUrl/api/inbound?ln1=$lon1&la1=$lat1&ln2=$lon2&la2=$lat2&ln3=$lon3&la3=$lat3&ln4=$lon4&la4=$lat4';
}
}
else{
if(indexController.currentUser.isNotEmpty){
bool _rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = _rog == true ? 'True': 'False';
var grp = indexController.currentUser[0]['user']['event_code'];
print("-------- requested user group $grp -------------");
url = '$serverUrl/api/inbound?rog=$r&grp=$grp&ln1=$lon1&la1=$lat1&ln2=$lon2&la2=$lat2&ln3=$lon3&la3=$lat3&ln4=$lon4&la4=$lat4';
}
else{
url = '$serverUrl/api/inbound?ln1=$lon1&la1=$lat1&ln2=$lon2&la2=$lat2&ln3=$lon3&la3=$lat3&ln4=$lon4&la4=$lat4';
}
}
print('++++++++$url');
final response = await http.get(Uri.parse(url),
//print('++++++++$url');
final response = await http.get(
Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
@ -181,51 +187,49 @@ class LocationService{
}
if (response.statusCode == 200) {
GeoJsonFeatureCollection cc = await featuresFromGeoJson(utf8.decode(response.bodyBytes));
if(cc.collection.isEmpty){
GeoJsonFeatureCollection cc =
await featuresFromGeoJson(utf8.decode(response.bodyBytes));
if (cc.collection.isEmpty) {
return null;
}
else{
} else {
//print("---- feature got from server is ${cc.collection[0].properties} ------");
return cc;
return cc;
}
}
return null;
}
static Future<GeoJsonFeatureCollection?> loadCustomLocations(String name, String cat) async {
static Future<GeoJsonFeatureCollection?> loadCustomLocations(
String name, String cat) async {
final IndexController indexController = Get.find<IndexController>();
String url = "";
if(cat == "-all-"){
if (cat == "-all-") {
cat = "";
}
String serverUrl = ConstValues.currentServer();
print("loadCustomLocations url is ----- $cat");
if(cat.isNotEmpty){
if(indexController.currentUser.isNotEmpty){
bool _rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = _rog == true ? 'True': 'False';
//print("loadCustomLocations url is ----- $cat");
if (cat.isNotEmpty) {
if (indexController.currentUser.isNotEmpty) {
bool rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = rog == true ? 'True' : 'False';
var grp = indexController.currentUser[0]['user']['event_code'];
url = '$serverUrl/api/custom_area/?rog=$r&&cat=' + cat;
url = '$serverUrl/api/custom_area/?rog=$r&&cat=$cat';
} else {
url = '$serverUrl/api/custom_area/?&cat=$cat';
}
else{
url = '$serverUrl/api/custom_area/?&cat=' + cat;
}
}
else{
if(indexController.currentUser.isNotEmpty){
bool _rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = _rog == true ? 'True': 'False';
} else {
if (indexController.currentUser.isNotEmpty) {
bool rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = rog == true ? 'True' : 'False';
var grp = indexController.currentUser[0]['user']['event_code'];
url = '$serverUrl/api/customarea?rog=$r&name=$name';
}
else{
} else {
url = '$serverUrl/api/customarea?name=$name';
}
}
print('++++++++$url');
final response = await http.get(Uri.parse(url),
//print('++++++++$url');
final response = await http.get(
Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
@ -236,18 +240,14 @@ class LocationService{
}
if (response.statusCode == 200) {
GeoJsonFeatureCollection cc = await featuresFromGeoJson(utf8.decode(response.bodyBytes));
if(cc.collection.isEmpty){
GeoJsonFeatureCollection cc =
await featuresFromGeoJson(utf8.decode(response.bodyBytes));
if (cc.collection.isEmpty) {
return null;
}
else{
return cc;
} else {
return cc;
}
}
return null;
}
}
}