2019-12-16 00:18:09 +00:00
|
|
|
import 'package:dio/dio.dart';
|
2020-07-08 13:13:24 +00:00
|
|
|
import 'package:geosmart/model/position.dart';
|
|
|
|
import 'package:geosmart/model/response.dart';
|
|
|
|
import 'package:geosmart/service/setting_service.dart';
|
2019-12-16 00:18:09 +00:00
|
|
|
|
2020-07-08 13:13:24 +00:00
|
|
|
class PositionService {
|
2019-12-16 00:18:09 +00:00
|
|
|
final Dio _dio = Dio();
|
2020-07-08 13:13:24 +00:00
|
|
|
final SettingService _settingBloc = SettingService();
|
2019-12-16 00:18:09 +00:00
|
|
|
|
2020-07-08 13:13:24 +00:00
|
|
|
PositionService();
|
2019-12-16 00:18:09 +00:00
|
|
|
|
|
|
|
Future<ResponseModel> sendPosition(String lat, String lng) async {
|
2020-07-08 13:13:24 +00:00
|
|
|
var m = await _settingBloc.getSetting();
|
2019-12-16 00:18:09 +00:00
|
|
|
Position position = new Position(
|
2020-07-08 13:13:24 +00:00
|
|
|
id: m.id,
|
2019-12-16 00:18:09 +00:00
|
|
|
type: "user",
|
|
|
|
lat: lat,
|
|
|
|
lng: lng,
|
|
|
|
);
|
|
|
|
try {
|
|
|
|
Response response = await _dio.post(
|
2020-07-08 13:13:24 +00:00
|
|
|
m.host + "/point/set",
|
2019-12-16 00:18:09 +00:00
|
|
|
data: position.toJson(),
|
|
|
|
);
|
|
|
|
return ResponseModel.fromJson(response.data);
|
|
|
|
} on DioError catch (e) {
|
2020-01-03 23:36:33 +00:00
|
|
|
print(e.response);
|
|
|
|
if (e.response != null) {
|
|
|
|
return ResponseModel.fromJson(e.response.data);
|
|
|
|
} else {
|
|
|
|
return ResponseModel.fromNull();
|
|
|
|
}
|
2019-12-16 00:18:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<ResponseModel> stopTracking() async {
|
2020-07-08 13:13:24 +00:00
|
|
|
var m = await _settingBloc.getSetting();
|
2019-12-16 00:18:09 +00:00
|
|
|
try {
|
|
|
|
Response response = await _dio.post(
|
2020-07-08 13:13:24 +00:00
|
|
|
m.host + "/point/unset",
|
2019-12-16 00:18:09 +00:00
|
|
|
data: {
|
2020-07-08 13:13:24 +00:00
|
|
|
"id": m.id,
|
2019-12-16 00:18:09 +00:00
|
|
|
"type": "user",
|
|
|
|
},
|
|
|
|
);
|
|
|
|
return ResponseModel.fromJson(response.data);
|
|
|
|
} on DioError catch (e) {
|
|
|
|
return ResponseModel.fromJson(e.response.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|