refactoring

This commit is contained in:
Mohamed Nouffer
2022-07-30 20:42:44 +05:30
parent a4adf24e99
commit 244b7eb9ac
14 changed files with 605 additions and 481 deletions

View File

@ -5,13 +5,21 @@ import 'package:google_fonts/google_fonts.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:rogapp/pages/index/index_binding.dart';
import 'package:rogapp/routes/app_pages.dart';
import 'package:rogapp/services/location_service.dart';
import 'package:rogapp/utils/string_values.dart';
void main() {
//WidgetsFlutterBinding.ensureInitialized();
initServices();
runApp(MyApp());
}
void initServices() async {
print('starting services ...');
await Get.putAsync(() => LocationService().init());
print('All services started...');
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.

View File

@ -1,93 +1,93 @@
class Destination {
String? name;
String? address;
String? phone;
String? email;
String? webcontents;
String? videos;
String? category;
int? series;
double? lat;
double? lon;
int? location_id;
int? list_order;
String? photos;
double? checkin_radious;
int? auto_checkin;
bool? selected = false;
bool? checkedin = false;
// class Destination {
// String? name;
// String? address;
// String? phone;
// String? email;
// String? webcontents;
// String? videos;
// String? category;
// int? series;
// double? lat;
// double? lon;
// int? location_id;
// int? list_order;
// String? photos;
// double? checkin_radious;
// int? auto_checkin;
// bool? selected = false;
// bool? checkedin = false;
Destination({
this.name,
this.address,
this.phone,
this.email,
this.webcontents,
this.videos,
this.category,
this.series,
this.lat,
this.lon,
this.location_id,
this.list_order,
this.photos,
this.checkin_radious,
this.auto_checkin,
this.selected,
this.checkedin
});
// Destination({
// this.name,
// this.address,
// this.phone,
// this.email,
// this.webcontents,
// this.videos,
// this.category,
// this.series,
// this.lat,
// this.lon,
// this.location_id,
// this.list_order,
// this.photos,
// this.checkin_radious,
// this.auto_checkin,
// this.selected,
// this.checkedin
// });
factory Destination.fromMap(Map<String, dynamic> json) {
// factory Destination.fromMap(Map<String, dynamic> json) {
bool selec = json['selected'] == 0 ? false : true;
bool checkin = json['checkedin'] == 0 ? false : true;
// bool selec = json['selected'] == 0 ? false : true;
// bool checkin = json['checkedin'] == 0 ? false : true;
return Destination(
name: json['name'],
address: json['address'],
phone: json['phone'],
email: json['email'],
webcontents: json['webcontents'],
videos: json['videos'],
category: json['category'],
series: json['series'],
lat: json['lat'],
lon: json['lon'],
location_id: json['location_id'],
list_order: json['list_order'],
photos: json['photos'],
checkin_radious: json['checkin_radious'],
auto_checkin:json['auto_checkin'],
selected: selec,
checkedin: checkin
);
}
// return Destination(
// name: json['name'],
// address: json['address'],
// phone: json['phone'],
// email: json['email'],
// webcontents: json['webcontents'],
// videos: json['videos'],
// category: json['category'],
// series: json['series'],
// lat: json['lat'],
// lon: json['lon'],
// location_id: json['location_id'],
// list_order: json['list_order'],
// photos: json['photos'],
// checkin_radious: json['checkin_radious'],
// auto_checkin:json['auto_checkin'],
// selected: selec,
// checkedin: checkin
// );
// }
Map<String, dynamic> toMap(){
int sel = selected == false ? 0 : 1;
int check = checkedin == false ? 0 : 1;
return {
'name':name,
'address': address,
'phone': phone,
'email': email,
'webcontents': webcontents,
'videos': videos,
'category':category,
'series':series,
'lat':lat,
'lon':lon,
'location_id':location_id,
'list_order':list_order,
'photos':photos,
'checkin_radious': checkin_radious,
'auto_checkin': auto_checkin,
'selected': sel,
'checkedin': check
};
}
// Map<String, dynamic> toMap(){
// int sel = selected == false ? 0 : 1;
// int check = checkedin == false ? 0 : 1;
// return {
// 'name':name,
// 'address': address,
// 'phone': phone,
// 'email': email,
// 'webcontents': webcontents,
// 'videos': videos,
// 'category':category,
// 'series':series,
// 'lat':lat,
// 'lon':lon,
// 'location_id':location_id,
// 'list_order':list_order,
// 'photos':photos,
// 'checkin_radious': checkin_radious,
// 'auto_checkin': auto_checkin,
// 'selected': sel,
// 'checkedin': check
// };
// }
}
// }

307
lib/model/location.dart Normal file
View File

@ -0,0 +1,307 @@
import 'package:geojson_vi/geojson_vi.dart';
import 'package:latlong2/latlong.dart';
class Location {
int? location_id;
String? location_name;
String? category;
String? zip;
String? address;
String? prefecture;
String? area;
String? city;
double? latitude;
double? longitude;
String? photos;
String? videos;
String? webcontents;
String? status;
String? portal;
String? group;
String? phone;
String? fax;
String? email;
String? facility;
String? remark;
String? tags;
String? event_name;
bool? event_active;
bool? hidden_location;
bool? auto_checkin;
int? checkin_radius;
int? checkin_point;
int? buy_point;
String? evaluation_value;
bool? shop_closed;
bool? shop_shutdown;
String? opening_hours_mon;
String? opening_hours_tue;
String? opening_hours_wed;
String? opening_hours_thu;
String? opening_hours_fri;
String? opening_hours_sat;
String? opening_hours_sun;
String? parammeters;
DateTime? created_at;
LatLng? geometry;
GeoJSONGeometry? multipoint;
Location({
this.location_id,
this.location_name,
this.category,
this.zip,
this.address,
this.prefecture,
this.area,
this.city,
this.latitude,
this.longitude,
this.photos,
this.videos,
this.webcontents,
this.status,
this.portal,
this.group,
this.phone,
this.fax,
this.email,
this.facility,
this.remark,
this.tags,
this.event_name,
this.event_active,
this.hidden_location,
this.auto_checkin,
this.checkin_radius,
this.checkin_point,
this.buy_point,
this.evaluation_value,
this.shop_closed,
this.shop_shutdown,
this.opening_hours_mon,
this.opening_hours_tue,
this.opening_hours_wed,
this.opening_hours_thu,
this.opening_hours_fri,
this.opening_hours_sat,
this.opening_hours_sun,
this.parammeters,
this.created_at,
this.geometry,
this.multipoint,
});
factory Location.fromMap(Map<String, dynamic> json){
bool is_event_active = json['event_active'] == 0 ? false : true;
bool is_hidden_location = json['hidden_location'] == 0 ? false : true;
bool is_auto_checkin = json['auto_checkin'] == 0 ? false : true;
bool is_shop_closed = json['shop_closed'] == 0 ? false : true;
bool is_shop_shutdown = json['shop_shutdown'] == 0 ? false : true;
return Location(
location_id: json['location_id'],
location_name: json['location_name'],
category: json['category'],
zip: json['zip'],
address: json['address'],
prefecture: json['prefecture'],
area: json['area'],
city: json['city'],
latitude: json['latitude'],
longitude: json['longitude'],
photos: json['photos'],
videos: json['videos'],
webcontents: json['webcontents'],
status: json['status'],
portal: json['portal'],
group: json['group'],
phone: json['phone'],
fax: json['fax'],
email: json['email'],
facility: json['facility'],
remark: json['remark'],
tags: json['tags'],
event_name: json['event_name'],
event_active: is_event_active,
hidden_location: is_hidden_location,
auto_checkin: is_auto_checkin,
checkin_radius: json['checkin_radius'],
checkin_point: json['checkin_point'],
buy_point: json['buy_point'],
evaluation_value: json['evaluation_value'],
shop_closed: is_shop_closed,
shop_shutdown: is_shop_shutdown,
opening_hours_mon: json['opening_hours_mon'],
opening_hours_tue: json['opening_hours_tue'],
opening_hours_wed: json['opening_hours_wed'],
opening_hours_thu: json['opening_hours_thu'],
opening_hours_fri: json['opening_hours_fri'],
opening_hours_sat: json['opening_hours_sat'],
opening_hours_sun: json['opening_hours_sun'],
parammeters: json['parammeters']
);
}
factory Location.fromGeoJSONFeture(GeoJSONFeature feature){
GeoJSONMultiPoint geom = feature.geometry as GeoJSONMultiPoint;
LatLng geomVal = LatLng(geom.coordinates[0][1], geom.coordinates[0][0]);
return Location(
location_id: feature.properties!["location_id"],
location_name: feature.properties!["location_name"],
category: feature.properties!["category"],
zip: feature.properties!["zip"],
address: feature.properties!["address"],
prefecture: feature.properties!["prefecture"],
area: feature.properties!["area"],
city: feature.properties!["city"],
latitude: feature.properties!["latitude"],
longitude: feature.properties!["longitude"],
phone: feature.properties!["phone"],
videos: feature.properties!["videos"],
webcontents: feature.properties!["webcontents"],
status: feature.properties!["status"],
portal: feature.properties!["portal"],
group: feature.properties!["group"],
photos: feature.properties!["photos"],
fax: feature.properties!["fax"],
email: feature.properties!["email"],
facility: feature.properties!["facility"],
remark: feature.properties!["remark"],
tags: feature.properties!["tags"],
event_name: feature.properties!["event_name"],
event_active: feature.properties!["event_active"],
hidden_location: feature.properties!["hidden_location"],
auto_checkin: feature.properties!["auto_checkin"],
checkin_radius: feature.properties!["checkin_radius"],
checkin_point: feature.properties!["checkin_point"],
buy_point: feature.properties!["buy_point"],
evaluation_value: feature.properties!["evaluation_value"],
shop_closed: feature.properties!["shop_closed"],
shop_shutdown: feature.properties!["shop_shutdown"],
opening_hours_mon: feature.properties!["opening_hours_mon"],
opening_hours_tue: feature.properties!["opening_hours_tue"],
opening_hours_wed: feature.properties!["opening_hours_wed"],
opening_hours_thu: feature.properties!["opening_hours_thu"],
opening_hours_fri: feature.properties!["opening_hours_fri"],
opening_hours_sat: feature.properties!["opening_hours_sat"],
opening_hours_sun: feature.properties!["opening_hours_sun"],
parammeters: feature.properties!["parammeters"],
created_at: DateTime.parse(feature.properties!["created_at"]),
geometry: geomVal,
multipoint: feature.geometry
);
}
Map<String, dynamic> toMap(){
int is_active = event_active == false ? 0 : 1;
int is_hidden = hidden_location == false ? 0 : 1;
int is_auto = auto_checkin == false ? 0 : 1;
int is_closed = shop_closed == false ? 0 : 1;
int is_shuldown = shop_shutdown == false ? 0 : 1;
return {
'location_id': location_id,
'location_name': location_name,
'category': category,
'zip': zip,
'address': address,
'prefecture': prefecture,
'area': area,
'city': city,
'latitude': latitude,
'longitude': longitude,
'phone': phone,
'videos': videos,
'webcontents': webcontents,
'status': status,
'portal': portal,
'group': group,
'photos':photos,
'fax': fax,
'email': email,
'facility': facility,
'remark': remark,
'tags': tags,
'event_name': event_name,
'event_active': event_active,
'hidden_location': hidden_location,
'auto_checkin': auto_checkin,
'checkin_radius': checkin_radius,
'checkin_point': checkin_point,
'buy_point': buy_point,
'evaluation_value': evaluation_value,
'shop_closed': shop_closed,
'shop_shutdown': shop_shutdown,
'opening_hours_mon': opening_hours_mon,
'opening_hours_tue': opening_hours_tue,
'opening_hours_wed': opening_hours_wed,
'opening_hours_thu': opening_hours_thu,
'opening_hours_fri': opening_hours_fri,
'opening_hours_sat': opening_hours_sat,
'opening_hours_sun': opening_hours_sun,
'parammeters': parammeters
};
}
GeoJSONFeature toGeoFeature(){
GeoJSONMultiPoint geom = multipoint as GeoJSONMultiPoint;
return GeoJSONFeature(
geom,
properties: {
'location_id': location_id,
'location_name': location_name,
'category': category,
'zip': zip,
'address': address,
'prefecture': prefecture,
'area': area,
'city': city,
'latitude': latitude,
'longitude': longitude,
'phone': phone,
'videos': videos,
'webcontents': webcontents,
'status': status,
'portal': portal,
'group': group,
'photos':photos,
'fax': fax,
'email': email,
'facility': facility,
'remark': remark,
'tags': tags,
'event_name': event_name,
'event_active': event_active,
'hidden_location': hidden_location,
'auto_checkin': auto_checkin,
'checkin_radius': checkin_radius,
'checkin_point': checkin_point,
'buy_point': buy_point,
'evaluation_value': evaluation_value,
'shop_closed': shop_closed,
'shop_shutdown': shop_shutdown,
'opening_hours_mon': opening_hours_mon,
'opening_hours_tue': opening_hours_tue,
'opening_hours_wed': opening_hours_wed,
'opening_hours_thu': opening_hours_thu,
'opening_hours_fri': opening_hours_fri,
'opening_hours_sat': opening_hours_sat,
'opening_hours_sun': opening_hours_sun,
'parammeters': parammeters,
'created_at': created_at,
}
);
}
}

View File

@ -1,14 +1,11 @@
import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:geojson/geojson.dart';
import 'package:geolocator/geolocator.dart';
import 'package:get/get.dart';
import 'package:latlong2/latlong.dart';
import 'package:rogapp/model/destination.dart';
import 'package:rogapp/model/location.dart';
import 'package:rogapp/pages/index/index_controller.dart';
import 'package:rogapp/routes/app_pages.dart';
import 'package:rogapp/services/destination_service.dart';
@ -24,10 +21,10 @@ class DestinationController extends GetxController {
late LocationSettings locationSettings;
var destinationCount = 0.obs;
List<Destination> destinations = <Destination>[].obs;
List<Location> destinations = <Location>[].obs;
List<Map<String, dynamic>> destination_index_data = <Map<String, dynamic>>[].obs;
List<Destination> currentSelectedDestinations = <Destination>[].obs;
List<Location> currentSelectedDestinations = <Location>[].obs;
bool checking_in = false;
List<bool> isSelected = [true].obs;
@ -42,23 +39,12 @@ class DestinationController extends GetxController {
final IndexController indexController = Get.find<IndexController>();
Future<Destination?> getDEstinationForLatLong(double lat, double long)async {
Future<Location?> getDEstinationForLatLong(double lat, double long)async {
String jjjj = '{"id":1,"type":"Feature","geometry":{"type":"MultiPoint","coordinates":[[136.731357,35.370094]]},"properties":{"location_id":915101,"location_name":"柳津","category":"買い物","zip":"〒501-6100","address":"柳津町字仙右城7696-1"}}';
for(final d in destinations){
// var geom = d["location"]["geometry"];
// var props = d["location"]["properties"];
// print("--props- ${d["location"]["geometry"]["coordinates"][0][1]}");
// List<dynamic> geom_multi = [geom];
// Map<String, dynamic> final_geom = {"features":[{"id":d["id"],"type":"Feature", "geometry": geom, "properties": props}]};
// //print("----- geom : ${final_geom}");
// String js = json.encode(final_geom);
// //print("---features-- ${js}-----");
// GeoJsonFeatureCollection features = await featuresFromGeoJson(js);
// GeoJsonMultiPoint p = features.collection[0].geometry as GeoJsonMultiPoint;
if(lat == d.lat && long == d.lon){
if(lat == d.latitude && long == d.longitude){
return d;
}
}
@ -71,56 +57,22 @@ class DestinationController extends GetxController {
if(!checking_in)
{
checking_in = true;
double lat = d.lat!;
double lon = d.lon!;
LatLng p = LatLng(lat, lon);
double lat = d.latitude!;
double lon = d.longitude!;
getDEstinationForLatLong(lat, lon).then((value){
var distance = Distance();
double dist = distance.as(LengthUnit.Meter, LatLng(lat, lon), LatLng(la, ln));
double rad = value!.checkin_radious ?? double.infinity;
int rad = value!.checkin_radius! ?? 1000000;
bool auto_checkin = value.auto_checkin == 0 ? false : true;
indexController.currentDestinationFeature.add(value);
//indexController.getAction();
if(rad >= dist){
if(auto_checkin){
makeCheckin(value, true);
}
else{
// showModalBottomSheet(context: Get.context!, isScrollControlled: true,
// builder:((context) => BottomSheetWidget())
// ).whenComplete((){
// checking_in = false;
// });
}
}
// if(!checking_in){
// checking_in = true;
// if(rad >= dist){
// if(auto_checkin){
// if(indexController.currentAction.isNotEmpty){
// print(indexController.currentAction[0]);
// indexController.currentAction[0][0]["checkin"] = true;
// Map<String,dynamic> temp = Map<String,dynamic>.from(indexController.currentAction[0][0]);
// indexController.currentAction.clear();
// print("---temp---${temp}");
// indexController.currentAction.add([temp]);
// }
// indexController.makeAction(Get.context!);
// }
// else{
// showModalBottomSheet(context: Get.context!, isScrollControlled: true,
// builder:((context) => BottomSheetWidget())
// ).whenComplete((){
// checking_in = false;
// });
// }
// }
// }
});
}
@ -128,12 +80,12 @@ class DestinationController extends GetxController {
}
}
void makeCheckin(Destination destination, bool action) async {
void makeCheckin(Location destination, bool action) async {
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ressssss ${action}@@@@@@@@@@@");
DatabaseHelper db = DatabaseHelper.instance;
int res = await db.updateAction(destination, action);
List<Destination> ddd = await db.getDestinationByLatLon(destination.lat!, destination.lon!);
List<Location> ddd = await db.getDestinationByLatLon(destination.lat!, destination.lon!);
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ddddd ${ddd[0].checkedin} @@@@@@@@@@@");
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ressssss ${res}@@@@@@@@@@@");

View File

@ -6,7 +6,6 @@ import 'package:flutter_map/plugin_api.dart';
import 'package:flutter_map_location_marker/flutter_map_location_marker.dart';
import 'package:flutter_map_marker_popup/flutter_map_marker_popup.dart';
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
import 'package:geojson/geojson.dart';
import 'package:geolocator/geolocator.dart';
import 'package:get/get.dart';
import 'package:latlong2/latlong.dart';

View File

@ -4,10 +4,10 @@ import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map/plugin_api.dart';
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
import 'package:geojson/geojson.dart';
import 'package:get/get.dart';
import 'package:latlong2/latlong.dart';
import 'package:rogapp/model/destination.dart';
import 'package:rogapp/model/location.dart';
import 'package:rogapp/pages/destination/destination_binding.dart';
import 'package:rogapp/pages/destination/destination_controller.dart';
import 'package:rogapp/pages/destination/destination_page.dart';
@ -21,9 +21,9 @@ import 'package:rogapp/services/perfecture_service.dart';
import 'package:rogapp/utils/database_helper.dart';
class IndexController extends GetxController {
List<GeoJsonFeatureCollection> locations = <GeoJsonFeatureCollection>[].obs;
List<GeoJsonFeature> currentFeature = <GeoJsonFeature>[].obs;
List<Destination> currentDestinationFeature = <Destination>[].obs;
List<Location> locations = <Location>[].obs;
List<Location> currentFeature = <Location>[].obs;
List<Location> currentDestinationFeature = <Location>[].obs;
List<dynamic> perfectures = <dynamic>[].obs;
List<LatLngBounds> currentBound = <LatLngBounds>[].obs;
List<dynamic> subPerfs = <dynamic>[].obs;
@ -62,6 +62,10 @@ class IndexController extends GetxController {
String areaDropdownValue = "-1";
String cateogory = "-all-";
LocationService locationService = Get.find<LocationService>();
late Worker _ever;
void toggleMode(){
@ -154,10 +158,10 @@ LatLngBounds boundsFromLatLngList(List<LatLng> list) {
List<LatLng> getLocationsList(){
List<LatLng> locs = [];
for(int i=0; i<= locations[0].collection.length - 1; i++){
GeoJsonMultiPoint p = locations[0].collection[i].geometry as GeoJsonMultiPoint;
for(int i=0; i<= locations.length - 1; i++){
Location p = locations[i];
LatLng latLng = LatLng(p.geoSerie!.geoPoints[0].latitude, p.geoSerie!.geoPoints[0].longitude);
LatLng latLng = LatLng(p.latitude!, p.longitude!);
locs.add(latLng);
}
return locs;
@ -172,9 +176,6 @@ void login(String email, String password, BuildContext context){
is_loading.value = false;
Navigator.pop(context);
loadUserDetails();
if(currentFeature.isNotEmpty){
getAction();
}
if(rog_mode.value == 1){
switchPage(AppPages.TRAVEL);
}
@ -222,18 +223,6 @@ void login(String email, String password, BuildContext context){
});
}
void makeAction(BuildContext context){
int user_id = currentUser[0]["user"]["id"] as int;
int location_id = currentFeature[0].properties!["location_id"] as int;
bool wanttogo = currentAction[0][0]["wanttogo"];
bool like = currentAction[0][0]["like"];
bool checkin = currentAction[0][0]["checkin"];
if(user_id > 0){
ActionService.makeAction(user_id, location_id, wanttogo, like, checkin).then((value){
});
}
}
void loadCatsv2(){
@ -272,22 +261,6 @@ void login(String email, String password, BuildContext context){
void refreshLocationForCat(){
loadLocationsBound();
// if(subDropdownValue == "-1"){
// LocationService.loadLocationsFor(dropdownValue, currentCat[0]).then((value){
// locations.clear();
// locations.add(value!);
// is_loading.value = false;
// });
// print("loading main------");
// }
// else{
// LocationService.loadLocationsSubFor(subDropdownValue, currentCat[0]).then((value){
// locations.clear();
// locations.add(value!);
// is_loading.value = false;
// });
// print("loading sub------");
// }
}
void loadAreaFor(String perf){
@ -349,11 +322,6 @@ void login(String email, String password, BuildContext context){
void loadLocationforPerf(String perf, MapController mapController) async {
String cat = currentCat.isNotEmpty == true ? currentCat[0] : "";
print(currentCat);
// LocationService.loadLocationsFor(perf, cat).then((value){
// locations.clear();
// locations.add(value!);
// mapController.fitBounds(currentBound[0]);
// });
locations.clear();
mapController.fitBounds(currentBound[0]);
}
@ -363,18 +331,18 @@ void login(String email, String password, BuildContext context){
if(currentCat[0] == "-all-"){
cat = "";
}
LocationService.loadLocationsSubFor(subperf, cat).then((value){
locationService.loadLocationsSubFor(subperf, cat).then((value){
locations.clear();
locations.add(value!);
locations.addAll(value);
});
}
void loadCustomLocation(String customarea) async {
String cat = currentCat.isNotEmpty == true ? currentCat[0] : "";
print("----- ${customarea}");
LocationService.loadCustomLocations(customarea, cat).then((value){
locationService.loadCustomLocations(customarea, cat).then((value){
locations.clear();
locations.add(value!);
locations.addAll(value);
List<LatLng> locs = getLocationsList();
LatLngBounds bounds = boundsFromLatLngList(locs);
mapController!.fitBounds(bounds);
@ -396,13 +364,13 @@ void login(String email, String password, BuildContext context){
currentBound.add(bounds);
//print(currentCat);
if(bounds.southEast != null && bounds.southWest != null && bounds.northEast != null && bounds.southEast != null ){
LocationService.loadLocationsBound(bounds.southWest!.latitude, bounds.southWest!.longitude, bounds.northWest.latitude, bounds.northWest.longitude, bounds.northEast!.latitude, bounds.northEast!.longitude, bounds.southEast.latitude, bounds.southEast.longitude, cat).then((value){
locationService.loadLocationsBound(bounds.southWest!.latitude, bounds.southWest!.longitude, bounds.northWest.latitude, bounds.northWest.longitude, bounds.northEast!.latitude, bounds.northEast!.longitude, bounds.southEast.latitude, bounds.southEast.longitude, cat).then((value){
//print("---value length ------ ${value!.collection.length}");
if(value == null){
return;
}
locations.clear();
if(value != null && value.collection.isEmpty){
if(value != null && value.isEmpty){
if(showPopup == false) {
return;
}
@ -418,9 +386,9 @@ void login(String email, String password, BuildContext context){
showPopup = false;
//Get.showSnackbar(GetSnackBar(message: "Too many points, please zoom in",));
}
if(value != null && value.collection.isNotEmpty){
if(value != null && value.isNotEmpty){
//print("---- added---");
locations.add(value);
locations.addAll(value);
loadCatsv2();
}
});
@ -482,104 +450,65 @@ void login(String email, String password, BuildContext context){
}
GeoJsonFeature? getFeatureForLatLong(double lat, double long){
Location? getFeatureForLatLong(double lat, double long){
if(locations.length > 0){
for(GeoJsonFeature i in locations[0].collection){
GeoJsonMultiPoint p = i.geometry as GeoJsonMultiPoint;
if(p.geoSerie!.geoPoints[0].latitude == lat && p.geoSerie!.geoPoints[0].longitude == long){
for(Location i in locations){
if(i.latitude == lat && i.longitude == long){
return i;
}
}
}
}
void getAction(){
//print(currentUser[0]["user"]["id"]);
//print(currentFeature[0].properties!["location_id"]);
if(currentUser.length == 0){
return;
}
int user_id = currentUser[0]["user"]["id"] as int;
print("---- loc id ${currentFeature[0].properties}");
int location_id = currentFeature[0].properties!["location_id"] as int;
ActionService.userAction(user_id, location_id).then((value){
print("------${value}");
if(value != null && value.length > 0){
currentAction.clear();
currentAction.add(value);
print("------${currentAction[0]}");
}else{
List<dynamic> initval = [{"user": user_id, "location": location_id, "wanttogo": false, "like": false, "checkin": false}];
currentAction.clear();
currentAction.add(initval);
}
});
}
void makeNext(GeoJsonFeature fs){
void makeNext(Location fs){
if(rog_mode == 1){
DestinationController destinationController = Get.find<DestinationController>();
print("---- destination index--- ${destinationController.destination_index_data} --------");
}
else {
GeoJsonFeature<GeoJsonMultiPoint> pt = fs as GeoJsonFeature<GeoJsonMultiPoint>;
for(int i=0; i<= locations[0].collection.length - 1; i++){
GeoJsonMultiPoint p = locations[0].collection[i].geometry as GeoJsonMultiPoint;
if(p.geoSerie!.geoPoints[0].latitude == pt.geometry!.geoSerie!.geoPoints[0].latitude && p.geoSerie!.geoPoints[0].longitude == pt.geometry!.geoSerie!.geoPoints[0].longitude ){
for(int i=0; i<= locations.length - 1; i++){
Location p = locations[i];
if(p.latitude == fs.latitude && p.longitude == fs.longitude ){
if(currentFeature.length > 0){
currentFeature.clear();
}
if(i >= locations[0].collection.length - 1 ){
currentFeature.add(locations[0].collection[0] as GeoJsonFeature);
getAction();
if(i >= locations.length - 1 ){
currentFeature.add(locations[0]);
}
else{
currentFeature.add(locations[0].collection[i + 1] as GeoJsonFeature);
getAction();
currentFeature.add(locations[i + 1]);
}
}
}
}
}
void makePrevious(GeoJsonFeature fs){
void makePrevious(Location fs){
if(rog_mode == 1){
DestinationController destinationController = Get.find<DestinationController>();
print("---- destination index--- ${destinationController.destination_index_data} --------");
}
else {
GeoJsonFeature<GeoJsonMultiPoint> pt = fs as GeoJsonFeature<GeoJsonMultiPoint>;
for(int i=0; i<= locations.length - 1; i++){
Location p = locations[i];
for(int i=0; i<= locations[0].collection.length - 1; i++){
GeoJsonMultiPoint p = locations[0].collection[i].geometry as GeoJsonMultiPoint;
if(p.geoSerie!.geoPoints[0].latitude == pt.geometry!.geoSerie!.geoPoints[0].latitude && p.geoSerie!.geoPoints[0].longitude == pt.geometry!.geoSerie!.geoPoints[0].longitude ){
if(p.latitude == fs.longitude && p.longitude == fs.longitude ){
if(currentFeature.length > 0){
currentFeature.clear();
}
if(i == 0 ){
currentFeature.add(locations[0].collection[locations[0].collection.length -1] as GeoJsonFeature);
getAction();
currentFeature.add(locations[locations.length -1]);
}
else{
currentFeature.add(locations[0].collection[i - 1] as GeoJsonFeature);
getAction();
currentFeature.add(locations[i - 1]);
}
}
}
}
}
}

View File

@ -1,7 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_typeahead/flutter_typeahead.dart';
import 'package:geojson/geojson.dart';
import 'package:get/get.dart';
import 'package:rogapp/pages/index/index_controller.dart';
import 'package:rogapp/pages/search/search_controller.dart';

View File

@ -1,35 +1,35 @@
import 'package:geojson/geojson.dart';
import 'package:http/http.dart' as http;
import '../utils/const.dart';
class LocationLineService{
static Future<GeoJsonFeature?> loadLocationLines() async {
final geo = GeoJson();
GeoJsonFeature? fs;
String server_url = ConstValues.currentServer();
String url = '${server_url}/api/location_line/';
//String url = 'http://localhost:8100/api/location_line/';
final response = await http.get(Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
);
// static Future<GeoJsonFeature?> loadLocationLines() async {
// final geo = GeoJson();
// GeoJsonFeature? fs;
// String server_url = ConstValues.currentServer();
// String url = '${server_url}/api/location_line/';
// //String url = 'http://localhost:8100/api/location_line/';
// final response = await http.get(Uri.parse(url),
// headers: <String, String>{
// 'Content-Type': 'application/json; charset=UTF-8',
// },
// );
if (response.statusCode == 200) {
// if (response.statusCode == 200) {
geo.processedFeatures.listen((fst) {
fs = fst;
});
// geo.processedFeatures.listen((fst) {
// fs = fst;
// });
await geo.parse(response.body, verbose:true);
// await geo.parse(response.body, verbose:true);
return fs;
// return fs;
} else {
throw Exception('Failed to create album.');
}
}
// } else {
// throw Exception('Failed to create album.');
// }
// }
}

View File

@ -1,36 +1,35 @@
import 'package:geojson/geojson.dart';
import 'package:http/http.dart' as http;
import '../utils/const.dart';
class LocationPolygonervice{
static Future<GeoJsonFeature?> loadLocationLines() async {
final geo = GeoJson();
GeoJsonFeature? fs;
// static Future<GeoJsonFeature?> loadLocationLines() async {
// final geo = GeoJson();
// GeoJsonFeature? fs;
String server_url = ConstValues.currentServer();
String url = '${server_url}/api/location_polygon/';
//String url = 'http://localhost:8100/api/location_polygon/';
final response = await http.get(Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
);
// String server_url = ConstValues.currentServer();
// String url = '${server_url}/api/location_polygon/';
// //String url = 'http://localhost:8100/api/location_polygon/';
// final response = await http.get(Uri.parse(url),
// headers: <String, String>{
// 'Content-Type': 'application/json; charset=UTF-8',
// },
// );
if (response.statusCode == 200) {
// if (response.statusCode == 200) {
geo.processedFeatures.listen((fst) {
fs = fst;
});
// geo.processedFeatures.listen((fst) {
// fs = fst;
// });
await geo.parse(response.body, verbose:true);
// await geo.parse(response.body, verbose:true);
return fs;
// return fs;
} else {
throw Exception('Failed to create album.');
}
}
// } else {
// throw Exception('Failed to create album.');
// }
// }
}

View File

@ -1,15 +1,20 @@
import 'dart:convert';
import 'package:geojson/geojson.dart';
import 'package:geojson_vi/geojson_vi.dart';
import 'package:get/get.dart';
import 'package:http/http.dart' as http;
import 'package:rogapp/model/location.dart';
import 'package:rogapp/utils/const.dart';
class LocationService{
class LocationService extends GetxService{
Future<LocationService> init() async {
print('$runtimeType ready!');
return this;
}
static Future<GeoJsonFeatureCollection?> loadLocations() async {
String server_url = ConstValues.currentServer();
String url = '${server_url}/api/location/';
//String url = 'http://localhost:8100/api/location/';
Future<List<Location>> loadLocations() async {
List<Location> locs = [];
String serverUrl = ConstValues.currentServer();
String url = '${serverUrl}/api/location/';
final response = await http.get(Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
@ -17,25 +22,29 @@ class LocationService{
);
if (response.statusCode == 200) {
return featuresFromGeoJson(utf8.decode(response.bodyBytes));
GeoJSONFeatureCollection coll = GeoJSONFeatureCollection.fromJSON(utf8.decode(response.bodyBytes));
for(int i=0; i<coll.features.length; i++ ){
GeoJSONFeature? gf = coll.features[i];
if(gf != null){
Location l = Location.fromGeoJSONFeture(gf);
locs.add(l);
}
}
}
return null;
return locs;
}
static Future<GeoJsonFeatureCollection?> loadLocationsFor(String perfecture, String cat) async {
Future<List<Location>> loadLocationsFor(String perfecture, String cat) async {
List<Location> locs = [];
String url = "";
String server_url = ConstValues.currentServer();
String serverUrl = ConstValues.currentServer();
if(cat.isNotEmpty){
url = '${server_url}/api/inperf/?perf=' + perfecture + '&cat=' + cat;
//url = 'http://localhost:8100/api/inperf/?perf=' + perfecture + '&cat=' + cat;
url = '${serverUrl}/api/inperf/?perf=' + perfecture + '&cat=' + cat;
}
else{
url = '${server_url}/api/inperf/?perf=' + perfecture;
//url = 'http://localhost:8100/api/inperf/?perf=' + perfecture;
url = '${serverUrl}/api/inperf/?perf=' + perfecture;
}
//print("----- url ---- ${url} --- ${cat}");
//String url = 'http://localhost:8100/api/inperf/?perf=' + perfecture + '&cat=' + cat;
final response = await http.get(Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
@ -43,25 +52,29 @@ class LocationService{
);
if (response.statusCode == 200) {
GeoJsonFeatureCollection cc = await featuresFromGeoJson(utf8.decode(response.bodyBytes));
//print(cc);
return cc; //featuresFromGeoJson(utf8.decode(response.bodyBytes));
GeoJSONFeatureCollection coll = GeoJSONFeatureCollection.fromJSON(utf8.decode(response.bodyBytes));
for(int i=0; i<coll.features.length; i++ ){
GeoJSONFeature? gf = coll.features[i];
if(gf != null){
Location l = Location.fromGeoJSONFeture(gf);
locs.add(l);
}
}
}
return null;
return locs;
}
static Future<GeoJsonFeatureCollection?> loadLocationsSubFor(String subperfecture, String cat) async {
Future<List<Location>> loadLocationsSubFor(String subperfecture, String cat) async {
List<Location> locs = [];
String url = "";
String server_url = ConstValues.currentServer();
if(cat.isNotEmpty){
url = '${server_url}/api/insubperf?subperf=' + subperfecture + '&cat=' + cat;
//url = 'http://localhost:8100/api/insubperf?subperf=' + subperfecture + '&cat=' + cat;
}
else{
print("------ loading location in sub----");
url = '${server_url}/api/insubperf?subperf=' + subperfecture;
//url = 'http://localhost:8100/api/insubperf?subperf=' + subperfecture;
}
final response = await http.get(Uri.parse(url),
headers: <String, String>{
@ -70,55 +83,52 @@ class LocationService{
);
if (response.statusCode == 200) {
GeoJsonFeatureCollection cc = await featuresFromGeoJson(utf8.decode(response.bodyBytes));
//print(cc);
return cc; //featuresFromGeoJson(utf8.decode(response.bodyBytes));
GeoJSONFeatureCollection coll = GeoJSONFeatureCollection.fromJSON(utf8.decode(response.bodyBytes));
for(int i=0; i<coll.features.length; i++ ){
GeoJSONFeature? gf = coll.features[i];
if(gf != null){
Location l = Location.fromGeoJSONFeture(gf);
locs.add(l);
}
}
}
return null;
return locs;
}
static Future<GeoJsonFeatureCollection?> loadLocationsBound(double lat1, double lon1, double lat2, double lon2, double lat3, double lon3, double lat4, double lon4, String cat) async {
Future<List<Location>> loadLocationsBound(double lat1, double lon1, double lat2, double lon2, double lat3, double lon3, double lat4, double lon4, String cat) async {
List<Location> locs = [];
String url = "";
String server_url = ConstValues.currentServer();
print("cat is ----- ${cat}");
//print("cat is ----- ${cat}");
if(cat.isNotEmpty){
url = '${server_url}/api/inbound?ln1=${lon1}&la1=${lat1}&ln2=${lon2}&la2=${lat2}&ln3=${lon3}&la3=${lat3}&ln4=${lon4}&la4=${lat4}' + '&cat=' + cat;
//url = 'http://localhost:8100/api/inbound?ln1=${lon1}&la1=${lat1}&ln2=${lon2}&la2=${lat2}&ln3=${lon3}&la3=${lat3}&ln4=${lon4}&la4=${lat4}' + '&cat=' + cat;
}
else{
url = '${server_url}/api/inbound?ln1=${lon1}&la1=${lat1}&ln2=${lon2}&la2=${lat2}&ln3=${lon3}&la3=${lat3}&ln4=${lon4}&la4=${lat4}';
//url = 'http://localhost:8100/api/inbound?ln1=${lon1}&la1=${lat1}&ln2=${lon2}&la2=${lat2}&ln3=${lon3}&la3=${lat3}&ln4=${lon4}&la4=${lat4}';
}
print("----url --- ${url}");
//print("----url --- ${url}");
final response = await http.get(Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
);
if (response.statusCode == 500) {
return GeoJsonFeatureCollection(); //featuresFromGeoJson(utf8.decode(response.bodyBytes));
}
if (response.statusCode == 200) {
GeoJsonFeatureCollection cc = await featuresFromGeoJson(utf8.decode(response.bodyBytes));
if(cc.collection.isEmpty){
return null;
}
else{
return cc;
GeoJSONFeatureCollection coll = GeoJSONFeatureCollection.fromJSON(utf8.decode(response.bodyBytes));
for(int i=0; i<coll.features.length; i++ ){
GeoJSONFeature? gf = coll.features[i];
if(gf != null){
Location l = Location.fromGeoJSONFeture(gf);
locs.add(l);
}
}
}
return null;
return locs;
}
static Future<GeoJsonFeatureCollection?> loadCustomLocations(String name, String cat) async {
Future<List<Location>> loadCustomLocations(String name, String cat) async {
List<Location> locs = [];
String url = "";
if(cat == "-all-"){
cat = "";
}
String server_url = ConstValues.currentServer();
print("cat is ----- ${cat}");
if(cat.isNotEmpty){
@ -136,23 +146,18 @@ class LocationService{
},
);
if (response.statusCode == 500) {
return GeoJsonFeatureCollection(); //featuresFromGeoJson(utf8.decode(response.bodyBytes));
}
if (response.statusCode == 200) {
GeoJsonFeatureCollection cc = await featuresFromGeoJson(utf8.decode(response.bodyBytes));
if(cc.collection.isEmpty){
return null;
}
else{
return cc;
if (response.statusCode == 200) {
GeoJSONFeatureCollection coll = GeoJSONFeatureCollection.fromJSON(utf8.decode(response.bodyBytes));
for(int i=0; i<coll.features.length; i++ ){
GeoJSONFeature? gf = coll.features[i];
if(gf != null){
Location l = Location.fromGeoJSONFeture(gf);
locs.add(l);
}
}
}
return null;
return locs;
}
}
}

View File

@ -1,6 +1,6 @@
import 'dart:io';
import 'package:path_provider/path_provider.dart';
import 'package:rogapp/model/destination.dart';
import 'package:rogapp/model/location.dart';
import 'package:sqflite/sqflite.dart';
import 'package:path/path.dart';
@ -22,44 +22,62 @@ class DatabaseHelper{
return openDatabase(join(await getDatabasesPath(), 'rog.db',), version: 1, onCreate: _onCreate);
}
Future _onCreate(Database db, int version) async {
await db.execute('''
CREATE TABLE destination(
location_id INTEGER PRIMARY KEY,
name TEXT,
address TEXT,
phone TEXT,
email TEXT,
webcontents TEXT,
videos TEXT,
location_name TEXT,
category TEXT,
series INTEGER,
lat REAL,
lon REAL,
list_order INTEGER,
zip TEXT,
address TEXT,
prefecture TEXT,
area TEXT,
city TEXT,
latitude REAL,
longitude REAL,
photos TEXT,
checkin_radious REAL,
fax TEXT,
email TEXT,
facility TEXT,
remark TEXT,
tags TEXT,
event_name TEXT,
event_active INTEGER,
hidden_location INTEGER,
auto_checkin INTEGER,
selected INTEGER,
checkedin INTEGER
checkin_radius INTEGER,
checkin_point INTEGER,
buy_point INTEGER,
evaluation_value TEXT,
shop_closed INTEGER,
shop_shutdown INTEGER,
opening_hours_mon TEXT,
opening_hours_tue TEXT,
opening_hours_wed TEXT,
opening_hours_thu TEXT,
opening_hours_fri TEXT,
opening_hours_sat TEXT,
opening_hours_sun TEXT
parammeters TEXT
)
''');
}
Future<List<Destination>> getDestinations() async {
Future<List<Location>> getDestinations() async {
Database db = await instance.database;
var dest = await db.query('destination');
List<Destination> destList = dest.isNotEmpty ?
dest.map((e) => Destination.fromMap(e)).toList() : [];
List<Location> destList = dest.isNotEmpty ?
dest.map((e) => Location.fromMap(e)).toList() : [];
print("--------- ${destList}");
return destList;
}
Future<List<Destination>> getDestinationByLatLon(double lat, double lon) async {
Future<List<Location>> getDestinationByLatLon(double lat, double lon) async {
Database db = await instance.database;
var dest = await db.query('destination', where: "lat = ${lat} and lon= ${lon}");
List<Destination> destList = dest.isNotEmpty
? dest.map((e) => Destination.fromMap(e)).toList() : [];
List<Location> destList = dest.isNotEmpty
? dest.map((e) => Location.fromMap(e)).toList() : [];
return destList;
}
@ -76,7 +94,7 @@ class DatabaseHelper{
return dest > 0 ? true : false;
}
Future<int> insertDestination(Destination dest) async {
Future<int> insertDestination(Location dest) async {
Database db = await instance.database;
int res = await db.insert(
'destination',
@ -87,7 +105,7 @@ class DatabaseHelper{
return res;
}
Future<int> updateAction(Destination destination, bool checkin)async {
Future<int> updateAction(Location destination, bool checkin)async {
Database db = await instance.database;
int act = checkin == false ? 0 : 1;
Map<String, dynamic> row = {
@ -101,10 +119,5 @@ class DatabaseHelper{
);
}
// Future<int?> getPending() async{
// Database db = await instance.database;
// return await Sqflite.firstIntValue(await db.rawQuery("SELECT COUNT(*) FROM incidents"));
// }
}

View File

@ -2,8 +2,7 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_map/plugin_api.dart';
import 'package:flutter_map_location_marker/flutter_map_location_marker.dart';
import 'package:flutter_map_marker_cluster/flutter_map_marker_cluster.dart';
import 'package:geojson/geojson.dart';
import 'package:flutter_map_marker_cluster/flutter_map_marker_cluster.dart';2
import 'package:get/get.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:latlong2/latlong.dart';
@ -64,62 +63,11 @@ class MapWidget extends StatelessWidget {
],
onPositionChanged: (MapPosition pos, isvalue){
// LatLng c1 = pos.center?? LatLng(0, 0);
// Timer(Duration(milliseconds:800), () {
// print(pos.bounds!.center);
// print("Yeah, this line is printed after 3 second");
// LatLng c2 = pos.center?? LatLng(0, 0);
// if(c1.latitude != 0 && c1.latitude == c2.latitude){
// print("------ calling ----");
// //indexController.loadLocationsBound();
// }
// });
//
},
onTap: (_, __) =>
_popupController
.hideAllPopups(), // Hide popup when the map is tapped.
),
layers: [
// MarkerLayerOptions(
// markers: indexController.locations[0].collection.map((i) {
// print("i si ${i.properties!['location_id']}");
// GeoJsonMultiPoint p = i.geometry as GeoJsonMultiPoint;
// print("lat is ${p.geoSerie!.geoPoints[0].latitude} and lon is ${p.geoSerie!.geoPoints[0].longitude}");
// return Marker(
// anchorPos: AnchorPos.align(AnchorAlign.center),
// height: 70.0,
// width: 70.0,
// point: LatLng(p.geoSerie!.geoPoints[0].latitude, p.geoSerie!.geoPoints[0].longitude),
// builder: (ctx) =>
// IconButton(
// icon: const Icon(Icons.pin_drop),
// tooltip: 'Increase volume by 10',
// onPressed: () {
// GeoJsonFeature? fs = indexController.getFeatureForLatLong(p.geoSerie!.geoPoints[0].latitude, p.geoSerie!.geoPoints[0].longitude);
// print(fs);
// if(fs != null){
// if(indexController.currentFeature.length > 0) {
// indexController.currentFeature.clear();
// }
// indexController.currentFeature.add(fs);
// indexController.getAction();
// showModalBottomSheet(context: context, isScrollControlled: true,
// builder:((context) => BottomSheetWidget())
// );
// }
// },
// ),
// );
// }).toList(),
// ),
],
children: [
BaseLayer(),
LocationMarkerLayerWidget(),

View File

@ -71,13 +71,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
extra_pedantic:
dependency: transitive
description:
name: extra_pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.0"
fake_async:
dependency: transitive
description:
@ -212,20 +205,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
geodesy:
dependency: transitive
description:
name: geodesy
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.0-nullsafety.0"
geojson:
geojson_vi:
dependency: "direct main"
description:
name: geojson
name: geojson_vi
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
version: "2.0.7"
geolocator:
dependency: "direct main"
description:
@ -268,13 +254,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.1"
geopoint:
dependency: transitive
description:
name: geopoint
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
get:
dependency: "direct main"
description:
@ -373,13 +352,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.17.0"
iso:
dependency: transitive
description:
name: iso
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
js:
dependency: transitive
description:
@ -581,13 +553,6 @@ packages:
description: flutter
source: sdk
version: "0.0.99"
slugify:
dependency: transitive
description:
name: slugify
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
source_span:
dependency: transitive
description:

View File

@ -56,8 +56,8 @@ dependencies:
material_design_icons_flutter: ^5.0.6595
google_fonts: any
image_picker: ^0.8.4+4
#geojson_vi: ^2.0.7
geojson: ^1.0.0
geojson_vi: ^2.0.7
#geojson: ^1.0.0
url_launcher: ^6.0.20
flutter_breadcrumb: ^1.0.1
timeline_tile: ^2.0.0