added rog local data

This commit is contained in:
Mohamed Nouffer
2022-11-14 22:22:41 +05:30
parent 78970ef5c3
commit 22a17e108c
10 changed files with 369 additions and 239 deletions

47
lib/model/rog.dart Normal file
View File

@ -0,0 +1,47 @@
class Rog {
int? id;
String? team_name;
String? event_code;
int? user_id;
int? cp_number;
int? checkintime;
String? image;
int? rog_action_type;
Rog({
this.id,
this.team_name,
this.event_code,
this.user_id,
this.cp_number,
this.checkintime,
this.image,
this.rog_action_type
});
factory Rog.fromMap(Map<String, dynamic> json){
return Rog(
id: json['id'],
team_name: json['team_name'],
event_code: json['event_code'],
user_id: json['user_id'],
cp_number: json['cp_number'],
checkintime: json['checkintime'],
image: json['image'],
rog_action_type: json['rog_action_type']
);
}
Map<String, dynamic> toMap(){
return {
'id': id,
'team_name' : team_name,
'event_code': event_code,
'user_id': user_id,
'cp_number': cp_number,
'checkintime': checkintime,
'image': image,
'rog_action_type': rog_action_type
};
}
}

View File

@ -70,6 +70,10 @@ class DestinationController extends GetxController {
int chekcs = 0; int chekcs = 0;
var rogaining_counted = false.obs; var rogaining_counted = false.obs;
String getFormatedTime(DateTime datetime){
return DateFormat('yyyy-MM-dd HH:mm:ss').format(datetime);
}
Destination festuretoDestination(GeoJsonFeature fs){ Destination festuretoDestination(GeoJsonFeature fs){
GeoJsonMultiPoint mp = fs.geometry as GeoJsonMultiPoint; GeoJsonMultiPoint mp = fs.geometry as GeoJsonMultiPoint;
LatLng pt = LatLng(mp.geoSerie!.geoPoints[0].latitude, mp.geoSerie!.geoPoints[0].longitude); LatLng pt = LatLng(mp.geoSerie!.geoPoints[0].latitude, mp.geoSerie!.geoPoints[0].longitude);
@ -278,96 +282,6 @@ class DestinationController extends GetxController {
} }
} }
// void startTimer2(Destination d, double distance) {
// skip_gps = true;
// print("---- in startTimer ----");
// double checkin_radious = d.checkin_radious ?? double.infinity;
// bool auto_checkin = d.auto_checkin == 0 ? false : true;
// bool location_already_checked_id = d.checkedin ?? false;
// bool isUser_logged_in = indexController.currentUser.length > 0 ? true : false;
// //make current destination
// print("---- checkin_radious ${checkin_radious} ----");
// print("---- distance ${distance} ----");
// if(checkin_radious >= distance){
// //currentSelectedDestinations.add(d);
// indexController.currentDestinationFeature.clear();
// indexController.currentDestinationFeature.add(d);
// print("---- checked in as ${indexController.currentDestinationFeature[0].checkedin.toString()} ----");
// }
// const oneSec = const Duration(seconds: 1);
// _timer = Timer.periodic(
// oneSec,
// (Timer timer) {
// if (_start == 0) {
// //make checkin
// print("---- location checkin radious ${d.checkin_radious} ----");
// print("---- already checked in ${location_already_checked_id} ----");
// if(checkin_radious >= distance && location_already_checked_id == false){
// if(auto_checkin){
// if(!checking_in){
// makeCheckin(d, true);
// if(d.cp != -1){
// rogaining_counted.value =true;
// }
// skip_gps = false;
// }
// }
// else{
// // ask for checkin
// _chekcs = 1;
// is_in_checkin.value = true;
// showModalBottomSheet(context: Get.context!, isScrollControlled: true,
// builder:((context) => BottomSheetNew())
// ).whenComplete((){
// skip_gps = false;
// _chekcs = 0;
// is_in_checkin.value = false;
// });
// }
// }
// if(isUser_logged_in && d.cp == -1 && location_already_checked_id){
// //check for rogaining
// if(is_at_goal.value == false && rogaining_counted.value){
// //goal
// print("---- in goal -----");
// _chekcs = 1;
// is_at_goal.value = true;
// showModalBottomSheet(context: Get.context!, isScrollControlled: true,
// builder:((context) => BottomSheetNew())
// ).whenComplete((){
// skip_gps = false;
// _chekcs = 0;
// is_at_goal.value = false;
// });
// }
// else if(is_in_rog.value == false){
// //start
// print("---- in start -----");
// _chekcs = 1;
// is_at_start.value = true;
// showModalBottomSheet(context: Get.context!, isScrollControlled: true,
// builder:((context) => BottomSheetNew())
// ).whenComplete((){
// skip_gps = false;
// _chekcs = 0;
// is_at_start.value = false;
// });
// }
// }
// timer.cancel();
// } else {
// _start--;
// }
// print("---- _chekcs ${_chekcs} ----");
// if(_chekcs == 0){
// skip_gps = false;
// }
// },
// );
// }
void resetRogaining(){ void resetRogaining(){
currentSelectedDestinations.forEach((element) { currentSelectedDestinations.forEach((element) {
deleteDestination(element); deleteDestination(element);
@ -479,19 +393,6 @@ class DestinationController extends GetxController {
print("--- made checkin ${df.location_id} ----"); print("--- made checkin ${df.location_id} ----");
makeCheckin(df, true, ""); makeCheckin(df, true, "");
} }
Rogaining rog = Rogaining(
rog_id: null,
course_id: 1,
user_id: indexController.currentUser[0]['user']['id'],
location_id: destination_id,
lat: lat,
lon:lon,
time_stamp: DateTime.now().toUtc().microsecondsSinceEpoch
);
db.insertRogaining(rog).then((value){
print("----- inserted value ${value} ---------");
});
is_in_rog.value = true; is_in_rog.value = true;
} }
@ -598,10 +499,35 @@ class DestinationController extends GetxController {
locationPermission.add(err.toString()); locationPermission.add(err.toString());
} }
ever(indexController.connectionStatusName, connectionChanged);
super.onInit(); super.onInit();
} }
void connectionChanged(String val) {
print('----- %%%%%%%%%%%%%%%%%%%%% ----- ${val}');
if(val == "wifi" || val == "mobile"){
String _token = indexController.currentUser[0]["token"];
DatabaseHelper db = DatabaseHelper.instance;
db.allRogianing().then((value){
value.forEach((e) {
if(e.rog_action_type == 0){
ExternalService().StartRogaining();
}
else if(e.rog_action_type == 1){
var datetime = new DateTime.fromMicrosecondsSinceEpoch(e.checkintime!);
ExternalService().makeCheckpoint(e.user_id!, _token, getFormatedTime(datetime), e.team_name!, e.cp_number!, e.event_code!, e.image!);
}
else if(e.rog_action_type == 2){
var datetime = new DateTime.fromMicrosecondsSinceEpoch(e.checkintime!);
ExternalService().makeGoal(e.user_id!, _token, e.team_name!, e.image!, getFormatedTime(datetime), e.event_code!);
}
});
});
}
}
void checkPermission() async { void checkPermission() async {
LocationPermission permission = await Geolocator.checkPermission(); LocationPermission permission = await Geolocator.checkPermission();
if (permission != LocationPermission.whileInUse || if (permission != LocationPermission.whileInUse ||

View File

@ -178,13 +178,8 @@ class DestnationPage extends StatelessWidget {
icon: Icon(Icons.accessibility), icon: Icon(Icons.accessibility),
), ),
), ),
// TextButton( // Obx(() =>
// onPressed: (){ // Text(indexController.connectionStatusName.value)
// //ExternalService().StartRogaining('team_name', "2222");
// //destinationController.openCamera(context);
// Get.toNamed(AppPages.CAMERA_PAGE);
// },
// child: Icon(Icons.ac_unit),
// ), // ),
Obx(() => Obx(() =>
ToggleButtons( ToggleButtons(

View File

@ -1,6 +1,8 @@
import 'dart:async'; import 'dart:async';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map/plugin_api.dart'; import 'package:flutter_map/plugin_api.dart';
import 'package:flutter_polyline_points/flutter_polyline_points.dart'; import 'package:flutter_polyline_points/flutter_polyline_points.dart';
@ -64,6 +66,11 @@ class IndexController extends GetxController {
late Worker _ever; late Worker _ever;
ConnectivityResult connectionStatus = ConnectivityResult.none;
var connectionStatusName = "".obs;
final Connectivity _connectivity = Connectivity();
late StreamSubscription<ConnectivityResult> _connectivitySubscription;
void toggleMode(){ void toggleMode(){
if(mode.value==0){ if(mode.value==0){
mode += 1; mode += 1;
@ -123,9 +130,35 @@ class IndexController extends GetxController {
//loadSubPerfFor("9"); //loadSubPerfFor("9");
}); });
} }
_connectivitySubscription = _connectivity.onConnectivityChanged.listen(_updateConnectionStatus);
super.onInit(); super.onInit();
} }
@override
void onClose() {
_connectivitySubscription.cancel();
super.onClose();
}
Future<void> _updateConnectionStatus(ConnectivityResult result) async {
connectionStatus = result;
connectionStatusName.value = result.name;
}
Future<void> initConnectivity() async {
late ConnectivityResult result;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
result = await _connectivity.checkConnectivity();
} on PlatformException catch (e) {
print('Couldn\'t check connectivity status --- $e');
return;
}
return _updateConnectionStatus(result);
}
LatLngBounds boundsFromLatLngList(List<LatLng> list) { LatLngBounds boundsFromLatLngList(List<LatLng> list) {
double? x0, x1, y0, y1; double? x0, x1, y0, y1;

View File

@ -1,11 +1,19 @@
import 'dart:io'; import 'dart:io';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:intl/intl.dart';
import 'package:rogapp/model/rog.dart';
import 'package:rogapp/pages/index/index_controller.dart'; import 'package:rogapp/pages/index/index_controller.dart';
import 'package:rogapp/utils/database_helper.dart';
import 'package:sqflite/sqlite_api.dart';
import 'dart:convert'; import 'dart:convert';
import '../utils/const.dart'; import '../utils/const.dart';
//
// Rog type 0- start 1- checkin 2- goal
//
class ExternalService { class ExternalService {
static final ExternalService _instance = ExternalService._internal(); static final ExternalService _instance = ExternalService._internal();
@ -15,35 +23,56 @@ class ExternalService {
ExternalService._internal(); ExternalService._internal();
String getFormatedTime(DateTime datetime){
return DateFormat('yyyy-MM-dd HH:mm:ss').format(datetime);
}
Future<Map<String, dynamic>> StartRogaining() async { Future<Map<String, dynamic>> StartRogaining() async {
Map<String, dynamic> _res = {};
final IndexController indexController = Get.find<IndexController>(); final IndexController indexController = Get.find<IndexController>();
Map<String, dynamic> _res = {};
int user_id = indexController.currentUser[0]["user"]["id"]; int user_id = indexController.currentUser[0]["user"]["id"];
//print("--- Pressed -----"); //print("--- Pressed -----");
String _team = indexController.currentUser[0]["user"]['team_name']; String _team = indexController.currentUser[0]["user"]['team_name'];
//print("--- _team : ${_team}-----"); //print("--- _team : ${_team}-----");
String _event_code = indexController.currentUser[0]["user"]["event_code"]; String _event_code = indexController.currentUser[0]["user"]["event_code"];
String url = 'https://natnats.mobilous.com/start_from_rogapp'; if(indexController.connectionStatusName != "wifi" || indexController.connectionStatusName != "mobile"){
//print('---- toekn is ${token} -----'); DatabaseHelper db = DatabaseHelper.instance;
final http.Response response = await http.post( Rog _rog = Rog(
Uri.parse(url), id:1,
headers: <String, String>{ team_name: _team,
'Content-Type': 'application/json; charset=UTF-8', event_code : _event_code,
}, user_id: user_id,
body: jsonEncode(<String, String>{ cp_number: -1,
'team_name': _team, checkintime: DateTime.now().toUtc().microsecondsSinceEpoch,
'event_code': _event_code image: null,
}), rog_action_type: 0
); );
db.insertRogaining(_rog);
}
else {
String url = 'https://natnats.mobilous.com/start_from_rogapp';
//print('---- toekn is ${token} -----');
final http.Response response = await http.post(
Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(<String, String>{
'team_name': _team,
'event_code': _event_code
}),
);
print("---- start rogianing api status ---- ${response.statusCode}"); print("---- start rogianing api status ---- ${response.statusCode}");
if (response.statusCode == 200) { if (response.statusCode == 200) {
_res = json.decode(utf8.decode(response.bodyBytes)); _res = json.decode(utf8.decode(response.bodyBytes));
print('----_res : ${_res} ----'); print('----_res : ${_res} ----');
}
} }
return _res; return _res;
} }
@ -51,56 +80,89 @@ class ExternalService {
Future<Map<String, dynamic>> makeCheckpoint(int user_id, String token, String checkin_time, String teamname, int cp, String eventcode, String imageurl) async { Future<Map<String, dynamic>> makeCheckpoint(int user_id, String token, String checkin_time, String teamname, int cp, String eventcode, String imageurl) async {
Map<String, dynamic> _res = {}; Map<String, dynamic> _res = {};
String url = 'https://natnats.mobilous.com/checkin_from_rogapp'; String url = 'https://natnats.mobilous.com/checkin_from_rogapp';
final IndexController indexController = Get.find<IndexController>();
if(imageurl != null){ if(imageurl != null){
String server_url = ConstValues.currentServer();
String url1 = "${server_url}/api/checkinimage/";
final im1Bytes = File(imageurl!).readAsBytesSync();
String im1_64 = base64Encode(im1Bytes);
final http.Response response = await http.post( if(indexController.connectionStatusName != "wifi" || indexController.connectionStatusName != "mobile"){
Uri.parse(url1), DatabaseHelper db = DatabaseHelper.instance;
headers: <String, String>{ Rog _rog = Rog(
'Content-Type': 'application/json; charset=UTF-8', id:1,
'Authorization': 'Token ${token}' team_name: teamname,
}, event_code : eventcode,
// 'id', 'user', 'goalimage', 'goaltime', 'team_name', 'event_code','cp_number' user_id: user_id,
body: jsonEncode(<String, String>{ cp_number: cp,
'user' : user_id.toString(), checkintime: DateTime.now().toUtc().microsecondsSinceEpoch,
'team_name': teamname, image: imageurl,
'event_code': eventcode, rog_action_type: 1,
'checkinimage' : im1_64,
'checkintime' : checkin_time,
'cp_number' : cp.toString()
}),
); );
db.insertRogaining(_rog);
}
else {
String server_url = ConstValues.currentServer();
String url1 = "${server_url}/api/checkinimage/";
final im1Bytes = File(imageurl!).readAsBytesSync();
String im1_64 = base64Encode(im1Bytes);
_res = json.decode(utf8.decode(response.bodyBytes)); final http.Response response = await http.post(
Uri.parse(url1),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'Token ${token}'
},
// 'id', 'user', 'goalimage', 'goaltime', 'team_name', 'event_code','cp_number'
body: jsonEncode(<String, String>{
'user' : user_id.toString(),
'team_name': teamname,
'event_code': eventcode,
'checkinimage' : im1_64,
'checkintime' : checkin_time,
'cp_number' : cp.toString()
}),
);
print("-----@@@@@ ${_res} -----"); _res = json.decode(utf8.decode(response.bodyBytes));
if(response.statusCode == 201){ print("-----@@@@@ ${_res} -----");
//print('---- toekn is ${token} -----');
final http.Response response2 = await http.post( if(response.statusCode == 201){
Uri.parse(url), //print('---- toekn is ${token} -----');
headers: <String, String>{ final http.Response response2 = await http.post(
'Content-Type': 'application/json; charset=UTF-8', Uri.parse(url),
}, headers: <String, String>{
body: jsonEncode(<String, String>{ 'Content-Type': 'application/json; charset=UTF-8',
'team_name': teamname, },
'cp_number': cp.toString(), body: jsonEncode(<String, String>{
'event_code': eventcode, 'team_name': teamname,
'image': _res["checkinimage"].toString().replaceAll('http://localhost:8100', 'http://rogaining.sumasen.net') 'cp_number': cp.toString(),
}), 'event_code': eventcode,
); 'image': _res["checkinimage"].toString().replaceAll('http://localhost:8100', 'http://rogaining.sumasen.net')
print("--- checnin response ${response2.statusCode}----"); }),
if (response2.statusCode == 200) { );
_res = json.decode(utf8.decode(response2.bodyBytes)); print("--- checnin response ${response2.statusCode}----");
print('----checkin res _res : ${_res} ----'); if (response2.statusCode == 200) {
} _res = json.decode(utf8.decode(response2.bodyBytes));
} print('----checkin res _res : ${_res} ----');
}
}
}
} }
else{ else{
if(indexController.connectionStatusName != "wifi" || indexController.connectionStatusName != "mobile"){
DatabaseHelper db = DatabaseHelper.instance;
Rog _rog = Rog(
id:1,
team_name: teamname,
event_code : eventcode,
user_id: user_id,
cp_number: cp,
checkintime: DateTime.now().toUtc().microsecondsSinceEpoch,
image: null,
rog_action_type: 1,
);
db.insertRogaining(_rog);
}
else {
final http.Response response3 = await http.post( final http.Response response3 = await http.post(
Uri.parse(url), Uri.parse(url),
headers: <String, String>{ headers: <String, String>{
@ -118,6 +180,7 @@ class ExternalService {
_res = json.decode(utf8.decode(response3.bodyBytes)); _res = json.decode(utf8.decode(response3.bodyBytes));
print('----checkin res _res : ${_res} ----'); print('----checkin res _res : ${_res} ----');
} }
}
} }
return _res; return _res;
} }
@ -126,50 +189,68 @@ class ExternalService {
Future<Map<String, dynamic>> makeGoal(int user_id, String token, String teamname, String image, String goal_time, String eventcode) async { Future<Map<String, dynamic>> makeGoal(int user_id, String token, String teamname, String image, String goal_time, String eventcode) async {
Map<String, dynamic> _res2 = {}; Map<String, dynamic> _res2 = {};
String server_url = ConstValues.currentServer(); final IndexController indexController = Get.find<IndexController>();
String url1 = "${server_url}/api/goalimage/";
final im1Bytes = File(image!).readAsBytesSync();
String im1_64 = base64Encode(im1Bytes);
final http.Response response = await http.post( if(indexController.connectionStatusName != "wifi" || indexController.connectionStatusName != "mobile"){
Uri.parse(url1), DatabaseHelper db = DatabaseHelper.instance;
headers: <String, String>{ Rog _rog = Rog(
'Content-Type': 'application/json; charset=UTF-8', id:1,
'Authorization': 'Token ${token}' team_name: teamname,
}, event_code : eventcode,
// 'id', 'user', 'goalimage', 'goaltime', 'team_name', 'event_code','cp_number' user_id: user_id,
body: jsonEncode(<String, String>{ cp_number: -1,
'user' : user_id.toString(), checkintime: DateTime.now().toUtc().microsecondsSinceEpoch,
'team_name': teamname, image: image,
'event_code': eventcode, rog_action_type: 1,
'goaltime' : goal_time, );
'goalimage' : im1_64, db.insertRogaining(_rog);
'cp_number' : "-1" }
}), else{
); String server_url = ConstValues.currentServer();
String url1 = "${server_url}/api/goalimage/";
final im1Bytes = File(image!).readAsBytesSync();
String im1_64 = base64Encode(im1Bytes);
String url = 'https://natnats.mobilous.com/goal_from_rogapp'; final http.Response response = await http.post(
//print("---response is : ${response.statusCode}----"); Uri.parse(url1),
if (response.statusCode == 201) { headers: <String, String>{
Map<String, dynamic> _res = json.decode(utf8.decode(response.bodyBytes)); 'Content-Type': 'application/json; charset=UTF-8',
print('----_res : ${_res} ----'); 'Authorization': 'Token ${token}'
print('---- image url ${_res["goalimage"]} ----'); },
final http.Response response2 = await http.post( // 'id', 'user', 'goalimage', 'goaltime', 'team_name', 'event_code','cp_number'
Uri.parse(url), body: jsonEncode(<String, String>{
headers: <String, String>{ 'user' : user_id.toString(),
'Content-Type': 'application/json; charset=UTF-8', 'team_name': teamname,
}, 'event_code': eventcode,
body: jsonEncode(<String, String>{ 'goaltime' : goal_time,
'team_name': teamname, 'goalimage' : im1_64,
'event_code': eventcode, 'cp_number' : "-1"
'goal_time' : goal_time, }),
'image' : _res["goalimage"].toString().replaceAll('http://localhost:8100', 'http://rogaining.sumasen.net')
}
),
); );
print('----- response2 is ${response2} --------');
if (response2.statusCode == 200) { String url = 'https://natnats.mobilous.com/goal_from_rogapp';
_res2 = json.decode(utf8.decode(response2.bodyBytes)); //print("---response is : ${response.statusCode}----");
if (response.statusCode == 201) {
Map<String, dynamic> _res = json.decode(utf8.decode(response.bodyBytes));
print('----_res : ${_res} ----');
print('---- image url ${_res["goalimage"]} ----');
final http.Response response2 = await http.post(
Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(<String, String>{
'team_name': teamname,
'event_code': eventcode,
'goal_time' : goal_time,
'image' : _res["goalimage"].toString().replaceAll('http://localhost:8100', 'http://rogaining.sumasen.net')
}
),
);
print('----- response2 is ${response2} --------');
if (response2.statusCode == 200) {
_res2 = json.decode(utf8.decode(response2.bodyBytes));
}
} }
} }
return _res2; return _res2;

View File

@ -5,6 +5,8 @@ import 'package:rogapp/model/destination.dart';
import 'package:sqflite/sqflite.dart'; import 'package:sqflite/sqflite.dart';
import 'package:path/path.dart'; import 'package:path/path.dart';
import '../model/rog.dart';
class DatabaseHelper{ class DatabaseHelper{
DatabaseHelper._privateConstructor(); DatabaseHelper._privateConstructor();
static final DatabaseHelper instance = DatabaseHelper._privateConstructor(); static final DatabaseHelper instance = DatabaseHelper._privateConstructor();
@ -58,43 +60,47 @@ class DatabaseHelper{
user_id INTEGER, user_id INTEGER,
lat REAL, lat REAL,
lon REAL, lon REAL,
time_stamp INTEGER time_stamp INTEGER,
image TEXT
) )
'''); ''');
await db.execute('''
CREATE TABLE rog(
id INTEGER PRIMARY KEY AUTOINCREMENT,
team_name TEXT,
event_code TEXT,
user_id INTEGER,
cp_number INTEGER,
checkintime INTEGER,
image TEXT,
rog_action_type INTEGER
)
''');
} }
Future<List<Rogaining>> allRogianing() async { Future<List<Rog>> allRogianing() async {
Database db = await instance.database; Database db = await instance.database;
var rog = await db.query('rogaining'); var rog = await db.query('rog');
List<Rogaining> roglist = rog.isNotEmpty ? List<Rog> roglist = rog.isNotEmpty ?
rog.map((e) => Rogaining.fromMap(e)).toList() : []; rog.map((e) => Rog.fromMap(e)).toList() : [];
print("--------- ${rog}"); print("--------- ${rog}");
return roglist; return roglist;
} }
Future<List<Rogaining>> getRogainingByLatLon(double lat, double lon) async { Future<List<Rog>> getRogainingByLatLon(double lat, double lon) async {
Database db = await instance.database; Database db = await instance.database;
var rog = await db.query('rogaining', where: "lat = ${lat} and lon= ${lon}"); var rog = await db.query('rog', where: "lat = ${lat} and lon= ${lon}");
List<Rogaining> roglist = rog.isNotEmpty List<Rog> roglist = rog.isNotEmpty
? rog.map((e) => Rogaining.fromMap(e)).toList() : []; ? rog.map((e) => Rog.fromMap(e)).toList() : [];
return roglist; return roglist;
} }
Future<List<Destination>> getDestinationById(int id) async { Future<int> deleteRogaining(int id) async {
Database db = await instance.database; Database db = await instance.database;
var rog = await db.query('destination', where: "location_id = ${id}"); var rog = await db.delete('rog', where: "id = ${id}");
List<Destination> deslist = rog.isNotEmpty
? rog.map((e) => Destination.fromMap(e)).toList() : [];
return deslist;
}
Future<int> deleteRogaining(int rog_id) async {
Database db = await instance.database;
var rog = await db.delete('rogaining', where: "rog_id = ${rog_id}");
int ret = rog > 0 ? rog : -1; int ret = rog > 0 ? rog : -1;
return ret; return ret;
@ -103,24 +109,24 @@ class DatabaseHelper{
Future<void> deleteAllRogaining() async { Future<void> deleteAllRogaining() async {
Database db = await instance.database; Database db = await instance.database;
await db.delete('rogaining'); await db.delete('rog');
} }
Future<bool>isRogAlreadyAvailable(int rog_id) async{ Future<bool>isRogAlreadyAvailable(int id) async{
Database db = await instance.database; Database db = await instance.database;
var rog = await db.query('rogaining', where: "rog_id = ${rog_id}"); var rog = await db.query('rog', where: "id = ${id}");
return rog.length > 0 ? true : false; return rog.length > 0 ? true : false;
} }
Future<int> insertRogaining(Rogaining rog) async { Future<int> insertRogaining(Rog rog) async {
Database db = await instance.database; Database db = await instance.database;
int? next_order = Sqflite.firstIntValue(await db.rawQuery('SELECT MAX(rog_id) FROM rogaining')); int? next_order = Sqflite.firstIntValue(await db.rawQuery('SELECT MAX(id) FROM rog'));
next_order = next_order==null ? 0 : next_order; next_order = next_order==null ? 0 : next_order;
next_order = next_order + 1; next_order = next_order + 1;
rog.rog_id = next_order; rog.id = next_order;
int res = await db.insert( int res = await db.insert(
'rogaining', 'rog',
rog.toMap(), rog.toMap(),
conflictAlgorithm: ConflictAlgorithm.replace, conflictAlgorithm: ConflictAlgorithm.replace,
); );
@ -138,6 +144,15 @@ class DatabaseHelper{
return destList; return destList;
} }
Future<List<Destination>> getDestinationById(int id) async {
Database db = await instance.database;
var rog = await db.query('destination', where: "location_id = ${id}");
List<Destination> deslist = rog.isNotEmpty
? rog.map((e) => Destination.fromMap(e)).toList() : [];
return deslist;
}
Future<List<Destination>> getDestinationByLatLon(double lat, double lon) async { Future<List<Destination>> getDestinationByLatLon(double lat, double lon) async {
Database db = await instance.database; Database db = await instance.database;
var dest = await db.query('destination', where: "lat = ${lat} and lon= ${lon}", orderBy: 'list_order'); var dest = await db.query('destination', where: "lat = ${lat} and lon= ${lon}", orderBy: 'list_order');

View File

@ -120,6 +120,20 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.16.0" version: "1.16.0"
connectivity_plus:
dependency: "direct main"
description:
name: connectivity_plus
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.2"
connectivity_plus_platform_interface:
dependency: transitive
description:
name: connectivity_plus_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.3"
cross_file: cross_file:
dependency: transitive dependency: transitive
description: description:
@ -141,6 +155,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.5" version: "1.0.5"
dbus:
dependency: transitive
description:
name: dbus
url: "https://pub.dartlang.org"
source: hosted
version: "0.7.8"
extra_pedantic: extra_pedantic:
dependency: transitive dependency: transitive
description: description:
@ -569,6 +590,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.2" version: "2.1.2"
nm:
dependency: transitive
description:
name: nm
url: "https://pub.dartlang.org"
source: hosted
version: "0.5.0"
path: path:
dependency: transitive dependency: transitive
description: description:

View File

@ -72,6 +72,7 @@ dependencies:
camera_camera: ^3.0.0-dev camera_camera: ^3.0.0-dev
intl: ^0.17.0 intl: ^0.17.0
modal_bottom_sheet: ^2.1.2 modal_bottom_sheet: ^2.1.2
connectivity_plus: ^3.0.2
flutter_icons: flutter_icons:
android: true android: true

View File

@ -6,11 +6,14 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <connectivity_plus/connectivity_plus_windows_plugin.h>
#include <geolocator_windows/geolocator_windows.h> #include <geolocator_windows/geolocator_windows.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h> #include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h> #include <url_launcher_windows/url_launcher_windows.h>
void RegisterPlugins(flutter::PluginRegistry* registry) { void RegisterPlugins(flutter::PluginRegistry* registry) {
ConnectivityPlusWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin"));
GeolocatorWindowsRegisterWithRegistrar( GeolocatorWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("GeolocatorWindows")); registry->GetRegistrarForPlugin("GeolocatorWindows"));
PermissionHandlerWindowsPluginRegisterWithRegistrar( PermissionHandlerWindowsPluginRegisterWithRegistrar(

View File

@ -3,6 +3,7 @@
# #
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
connectivity_plus
geolocator_windows geolocator_windows
permission_handler_windows permission_handler_windows
url_launcher_windows url_launcher_windows