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';
|
2020-07-28 18:11:47 +00:00
|
|
|
import 'package:meta/meta.dart';
|
2019-12-16 00:18:09 +00:00
|
|
|
|
2020-07-08 13:13:24 +00:00
|
|
|
class PositionService {
|
2020-07-28 18:11:47 +00:00
|
|
|
final Dio dio;
|
2020-07-08 13:13:24 +00:00
|
|
|
final SettingService _settingBloc = SettingService();
|
2019-12-16 00:18:09 +00:00
|
|
|
|
2020-07-28 18:11:47 +00:00
|
|
|
PositionService({
|
|
|
|
@required this.dio,
|
|
|
|
});
|
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 {
|
2020-07-28 18:11:47 +00:00
|
|
|
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-07-28 18:11:47 +00:00
|
|
|
throw (e);
|
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 {
|
2020-07-28 18:11:47 +00:00
|
|
|
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) {
|
2020-07-28 18:11:47 +00:00
|
|
|
throw (e);
|
2019-12-16 00:18:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|