|
|
@@ -11,8 +11,12 @@ import 'package:location/data/repositories/account_repository.dart';
|
|
|
import 'package:location/data/repositories/friends_repository.dart';
|
|
|
import 'package:location/data/repositories/track_repository.dart';
|
|
|
import 'package:location/handler/error_handler.dart';
|
|
|
+import 'package:location/resource/string.gen.dart';
|
|
|
import 'package:sliding_sheet2/sliding_sheet2.dart';
|
|
|
import '../../data/bean/user_info.dart';
|
|
|
+import '../../dialog/location_permission_dialog.dart';
|
|
|
+import '../../sdk/map/map_helper.dart';
|
|
|
+import '../../utils/permission_util.dart';
|
|
|
|
|
|
@injectable
|
|
|
class TrackController extends BaseController
|
|
|
@@ -33,6 +37,10 @@ class TrackController extends BaseController
|
|
|
|
|
|
final Rxn<TrackDays> currentTrackDay = Rxn();
|
|
|
|
|
|
+ final RxDouble _sheetProgress = 0.0.obs;
|
|
|
+
|
|
|
+ double get sheetProgress => _sheetProgress.value;
|
|
|
+
|
|
|
final mapPadding =
|
|
|
MapPadding(left: 50.w, top: 100.w, right: 50.w, bottom: Get.height / 2);
|
|
|
|
|
|
@@ -136,11 +144,79 @@ class TrackController extends BaseController
|
|
|
}
|
|
|
|
|
|
void _clearSelectMapMarker() {
|
|
|
+ mapController.removeMarker(Constants.mineLocationId);
|
|
|
mapController.removePolyline(Constants.traceSelectLineId);
|
|
|
mapController.removeMarker(Constants.tracePopupId);
|
|
|
mapController.removeMarker(Constants.traceErrorId);
|
|
|
}
|
|
|
|
|
|
+ setSheetProgress(double progress) {
|
|
|
+ _sheetProgress.value = progress;
|
|
|
+ }
|
|
|
+
|
|
|
+ void onCurrentLocationClick() async {
|
|
|
+ //权限检查
|
|
|
+ bool isGranted = await PermissionUtil.checkLocationPermission();
|
|
|
+ if (!isGranted) {
|
|
|
+ LocationPermissionDialog.show(onNextStep: _requestLocationPermission);
|
|
|
+ } else {
|
|
|
+ _updateCurrentLocation();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void _updateCurrentLocation() {
|
|
|
+ var lastLocation = MapHelper.getLastLocation();
|
|
|
+ if (lastLocation == null) {
|
|
|
+ locationListener(MapLocation location) {
|
|
|
+ MapHelper.removeLocationListener(locationListener);
|
|
|
+ showMineLocationMarker(location);
|
|
|
+ }
|
|
|
+
|
|
|
+ MapHelper.addLocationListener(locationListener);
|
|
|
+ } else {
|
|
|
+ showMineLocationMarker(lastLocation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void showMineLocationMarker(MapLocation location) {
|
|
|
+ _clearSelectMapMarker();
|
|
|
+ Marker mineMarker = Marker(
|
|
|
+ id: Constants.mineLocationId,
|
|
|
+ latitude: location.latitude,
|
|
|
+ longitude: location.longitude,
|
|
|
+ isSelected: false,
|
|
|
+ customAvatarUrl: accountRepository.mineUserInfo.value.avatar,
|
|
|
+ markerName: StringName.locationMine,
|
|
|
+ markerType: MarkerType.mine);
|
|
|
+ mapController.updateOrAddMarker(mineMarker);
|
|
|
+ animateCamera(latitude: location.latitude, longitude: location.longitude);
|
|
|
+ }
|
|
|
+
|
|
|
+ void animateCamera({required double? latitude, required double? longitude}) {
|
|
|
+ mapController.animateCamera(
|
|
|
+ CameraPosition(longitude: longitude, latitude: latitude, zoom: 18));
|
|
|
+ }
|
|
|
+
|
|
|
+ void _requestLocationPermission() async {
|
|
|
+ bool isGranted = await PermissionUtil.requestLocationPermission();
|
|
|
+ if (isGranted) {
|
|
|
+ _showLocationAlways();
|
|
|
+ _updateCurrentLocation();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void _showLocationAlways() async {
|
|
|
+ bool isGranted = await PermissionUtil.checkShowLocationAlways();
|
|
|
+ if (!isGranted) {
|
|
|
+ LocationAlwaysPermissionDialog.show(onNextStep: () async {
|
|
|
+ isGranted = await PermissionUtil.requestShowLocationAlways();
|
|
|
+ if (isGranted) {
|
|
|
+ _updateCurrentLocation();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@override
|
|
|
void onClose() {
|
|
|
super.onClose();
|