added rog local data
This commit is contained in:
47
lib/model/rog.dart
Normal file
47
lib/model/rog.dart
Normal 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
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -70,6 +70,10 @@ class DestinationController extends GetxController {
|
||||
int chekcs = 0;
|
||||
var rogaining_counted = false.obs;
|
||||
|
||||
String getFormatedTime(DateTime datetime){
|
||||
return DateFormat('yyyy-MM-dd HH:mm:ss').format(datetime);
|
||||
}
|
||||
|
||||
Destination festuretoDestination(GeoJsonFeature fs){
|
||||
GeoJsonMultiPoint mp = fs.geometry as GeoJsonMultiPoint;
|
||||
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(){
|
||||
currentSelectedDestinations.forEach((element) {
|
||||
deleteDestination(element);
|
||||
@ -479,19 +393,6 @@ class DestinationController extends GetxController {
|
||||
print("--- made checkin ${df.location_id} ----");
|
||||
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;
|
||||
}
|
||||
|
||||
@ -598,10 +499,35 @@ class DestinationController extends GetxController {
|
||||
locationPermission.add(err.toString());
|
||||
}
|
||||
|
||||
ever(indexController.connectionStatusName, connectionChanged);
|
||||
|
||||
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 {
|
||||
LocationPermission permission = await Geolocator.checkPermission();
|
||||
if (permission != LocationPermission.whileInUse ||
|
||||
|
||||
@ -178,13 +178,8 @@ class DestnationPage extends StatelessWidget {
|
||||
icon: Icon(Icons.accessibility),
|
||||
),
|
||||
),
|
||||
// TextButton(
|
||||
// onPressed: (){
|
||||
// //ExternalService().StartRogaining('team_name', "2222");
|
||||
// //destinationController.openCamera(context);
|
||||
// Get.toNamed(AppPages.CAMERA_PAGE);
|
||||
// },
|
||||
// child: Icon(Icons.ac_unit),
|
||||
// Obx(() =>
|
||||
// Text(indexController.connectionStatusName.value)
|
||||
// ),
|
||||
Obx(() =>
|
||||
ToggleButtons(
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:flutter_map/plugin_api.dart';
|
||||
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
|
||||
@ -64,6 +66,11 @@ class IndexController extends GetxController {
|
||||
|
||||
late Worker _ever;
|
||||
|
||||
ConnectivityResult connectionStatus = ConnectivityResult.none;
|
||||
var connectionStatusName = "".obs;
|
||||
final Connectivity _connectivity = Connectivity();
|
||||
late StreamSubscription<ConnectivityResult> _connectivitySubscription;
|
||||
|
||||
void toggleMode(){
|
||||
if(mode.value==0){
|
||||
mode += 1;
|
||||
@ -123,9 +130,35 @@ class IndexController extends GetxController {
|
||||
//loadSubPerfFor("9");
|
||||
});
|
||||
}
|
||||
|
||||
_connectivitySubscription = _connectivity.onConnectivityChanged.listen(_updateConnectionStatus);
|
||||
|
||||
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) {
|
||||
double? x0, x1, y0, y1;
|
||||
|
||||
@ -1,11 +1,19 @@
|
||||
import 'dart:io';
|
||||
import 'package:get/get.dart';
|
||||
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/utils/database_helper.dart';
|
||||
import 'package:sqflite/sqlite_api.dart';
|
||||
import 'dart:convert';
|
||||
|
||||
import '../utils/const.dart';
|
||||
|
||||
//
|
||||
// Rog type 0- start 1- checkin 2- goal
|
||||
//
|
||||
|
||||
class ExternalService {
|
||||
static final ExternalService _instance = ExternalService._internal();
|
||||
|
||||
@ -15,35 +23,56 @@ class ExternalService {
|
||||
|
||||
ExternalService._internal();
|
||||
|
||||
String getFormatedTime(DateTime datetime){
|
||||
return DateFormat('yyyy-MM-dd HH:mm:ss').format(datetime);
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> StartRogaining() async {
|
||||
Map<String, dynamic> _res = {};
|
||||
|
||||
final IndexController indexController = Get.find<IndexController>();
|
||||
|
||||
|
||||
Map<String, dynamic> _res = {};
|
||||
|
||||
int user_id = indexController.currentUser[0]["user"]["id"];
|
||||
//print("--- Pressed -----");
|
||||
String _team = indexController.currentUser[0]["user"]['team_name'];
|
||||
//print("--- _team : ${_team}-----");
|
||||
String _event_code = indexController.currentUser[0]["user"]["event_code"];
|
||||
|
||||
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
|
||||
}),
|
||||
);
|
||||
if(indexController.connectionStatusName != "wifi" || indexController.connectionStatusName != "mobile"){
|
||||
DatabaseHelper db = DatabaseHelper.instance;
|
||||
Rog _rog = Rog(
|
||||
id:1,
|
||||
team_name: _team,
|
||||
event_code : _event_code,
|
||||
user_id: user_id,
|
||||
cp_number: -1,
|
||||
checkintime: DateTime.now().toUtc().microsecondsSinceEpoch,
|
||||
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) {
|
||||
_res = json.decode(utf8.decode(response.bodyBytes));
|
||||
print('----_res : ${_res} ----');
|
||||
if (response.statusCode == 200) {
|
||||
_res = json.decode(utf8.decode(response.bodyBytes));
|
||||
print('----_res : ${_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 {
|
||||
Map<String, dynamic> _res = {};
|
||||
String url = 'https://natnats.mobilous.com/checkin_from_rogapp';
|
||||
final IndexController indexController = Get.find<IndexController>();
|
||||
|
||||
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(
|
||||
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()
|
||||
}),
|
||||
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: imageurl,
|
||||
rog_action_type: 1,
|
||||
);
|
||||
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('---- toekn is ${token} -----');
|
||||
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,
|
||||
'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('----checkin res _res : ${_res} ----');
|
||||
}
|
||||
}
|
||||
print("-----@@@@@ ${_res} -----");
|
||||
|
||||
if(response.statusCode == 201){
|
||||
//print('---- toekn is ${token} -----');
|
||||
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,
|
||||
'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('----checkin res _res : ${_res} ----');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
@ -118,6 +180,7 @@ class ExternalService {
|
||||
_res = json.decode(utf8.decode(response3.bodyBytes));
|
||||
print('----checkin res _res : ${_res} ----');
|
||||
}
|
||||
}
|
||||
}
|
||||
return _res;
|
||||
}
|
||||
@ -125,52 +188,70 @@ class ExternalService {
|
||||
|
||||
Future<Map<String, dynamic>> makeGoal(int user_id, String token, String teamname, String image, String goal_time, String eventcode) async {
|
||||
Map<String, dynamic> _res2 = {};
|
||||
|
||||
String server_url = ConstValues.currentServer();
|
||||
String url1 = "${server_url}/api/goalimage/";
|
||||
final im1Bytes = File(image!).readAsBytesSync();
|
||||
String im1_64 = base64Encode(im1Bytes);
|
||||
|
||||
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,
|
||||
'goaltime' : goal_time,
|
||||
'goalimage' : im1_64,
|
||||
'cp_number' : "-1"
|
||||
}),
|
||||
);
|
||||
final IndexController indexController = Get.find<IndexController>();
|
||||
|
||||
String url = 'https://natnats.mobilous.com/goal_from_rogapp';
|
||||
//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')
|
||||
}
|
||||
),
|
||||
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: -1,
|
||||
checkintime: DateTime.now().toUtc().microsecondsSinceEpoch,
|
||||
image: image,
|
||||
rog_action_type: 1,
|
||||
);
|
||||
db.insertRogaining(_rog);
|
||||
}
|
||||
else{
|
||||
String server_url = ConstValues.currentServer();
|
||||
String url1 = "${server_url}/api/goalimage/";
|
||||
final im1Bytes = File(image!).readAsBytesSync();
|
||||
String im1_64 = base64Encode(im1Bytes);
|
||||
|
||||
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,
|
||||
'goaltime' : goal_time,
|
||||
'goalimage' : im1_64,
|
||||
'cp_number' : "-1"
|
||||
}),
|
||||
);
|
||||
print('----- response2 is ${response2} --------');
|
||||
if (response2.statusCode == 200) {
|
||||
_res2 = json.decode(utf8.decode(response2.bodyBytes));
|
||||
}
|
||||
|
||||
String url = 'https://natnats.mobilous.com/goal_from_rogapp';
|
||||
//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;
|
||||
}
|
||||
|
||||
@ -5,6 +5,8 @@ import 'package:rogapp/model/destination.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
import 'package:path/path.dart';
|
||||
|
||||
import '../model/rog.dart';
|
||||
|
||||
class DatabaseHelper{
|
||||
DatabaseHelper._privateConstructor();
|
||||
static final DatabaseHelper instance = DatabaseHelper._privateConstructor();
|
||||
@ -58,43 +60,47 @@ class DatabaseHelper{
|
||||
user_id INTEGER,
|
||||
lat 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;
|
||||
var rog = await db.query('rogaining');
|
||||
List<Rogaining> roglist = rog.isNotEmpty ?
|
||||
rog.map((e) => Rogaining.fromMap(e)).toList() : [];
|
||||
var rog = await db.query('rog');
|
||||
List<Rog> roglist = rog.isNotEmpty ?
|
||||
rog.map((e) => Rog.fromMap(e)).toList() : [];
|
||||
print("--------- ${rog}");
|
||||
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;
|
||||
var rog = await db.query('rogaining', where: "lat = ${lat} and lon= ${lon}");
|
||||
List<Rogaining> roglist = rog.isNotEmpty
|
||||
? rog.map((e) => Rogaining.fromMap(e)).toList() : [];
|
||||
var rog = await db.query('rog', where: "lat = ${lat} and lon= ${lon}");
|
||||
List<Rog> roglist = rog.isNotEmpty
|
||||
? rog.map((e) => Rog.fromMap(e)).toList() : [];
|
||||
return roglist;
|
||||
}
|
||||
|
||||
Future<List<Destination>> getDestinationById(int id) async {
|
||||
Future<int> deleteRogaining(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<int> deleteRogaining(int rog_id) async {
|
||||
Database db = await instance.database;
|
||||
var rog = await db.delete('rogaining', where: "rog_id = ${rog_id}");
|
||||
var rog = await db.delete('rog', where: "id = ${id}");
|
||||
int ret = rog > 0 ? rog : -1;
|
||||
|
||||
return ret;
|
||||
@ -103,24 +109,24 @@ class DatabaseHelper{
|
||||
|
||||
Future<void> deleteAllRogaining() async {
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
Future<int> insertRogaining(Rogaining rog) async {
|
||||
Future<int> insertRogaining(Rog rog) async {
|
||||
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 + 1;
|
||||
rog.rog_id = next_order;
|
||||
rog.id = next_order;
|
||||
int res = await db.insert(
|
||||
'rogaining',
|
||||
'rog',
|
||||
rog.toMap(),
|
||||
conflictAlgorithm: ConflictAlgorithm.replace,
|
||||
);
|
||||
@ -138,6 +144,15 @@ class DatabaseHelper{
|
||||
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 {
|
||||
Database db = await instance.database;
|
||||
var dest = await db.query('destination', where: "lat = ${lat} and lon= ${lon}", orderBy: 'list_order');
|
||||
|
||||
Reference in New Issue
Block a user