|
|
|
|
@ -2,15 +2,12 @@ import 'dart:async';
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/foundation.dart' show ChangeNotifier;
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:google_maps_flutter_platform_interface/src/types/camera.dart';
|
|
|
|
|
import 'package:google_maps_flutter/google_maps_flutter.dart' as GMSMapServices;
|
|
|
|
|
import 'package:hmg_patient_app_new/features/location/GeocodeResponse.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/features/location/PlaceDetails.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/features/location/location_repo.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/services/error_handler_service.dart';
|
|
|
|
|
import 'package:huawei_map/huawei_map.dart' as HMSCameraServices;
|
|
|
|
|
import 'package:google_maps_flutter/google_maps_flutter.dart' as GMSMapServices;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import 'PlacePrediction.dart';
|
|
|
|
|
|
|
|
|
|
@ -20,8 +17,8 @@ class LocationViewModel extends ChangeNotifier {
|
|
|
|
|
|
|
|
|
|
LocationViewModel({required this.locationRepo, required this.errorHandlerService});
|
|
|
|
|
|
|
|
|
|
List<PlacePrediction> predictions = [];
|
|
|
|
|
PlacePrediction? selectedPrediction;
|
|
|
|
|
List<PlacePrediction> predictions = [];
|
|
|
|
|
PlacePrediction? selectedPrediction;
|
|
|
|
|
bool isPredictionLoading = false;
|
|
|
|
|
GeocodeResponse? geocodeResponse;
|
|
|
|
|
PlaceDetails? placeDetails;
|
|
|
|
|
@ -30,14 +27,14 @@ class LocationViewModel extends ChangeNotifier {
|
|
|
|
|
|
|
|
|
|
FutureOr<void> getPlacesPrediction(String input) async {
|
|
|
|
|
predictions = [];
|
|
|
|
|
isPredictionLoading= true;
|
|
|
|
|
isPredictionLoading = true;
|
|
|
|
|
final result = await locationRepo.getPlacePredictionsAsInput(input);
|
|
|
|
|
result.fold(
|
|
|
|
|
(failure) {
|
|
|
|
|
errorHandlerService.handleError(failure: failure);
|
|
|
|
|
},
|
|
|
|
|
(apiModel) {
|
|
|
|
|
predictions = apiModel.data??[];
|
|
|
|
|
predictions = apiModel.data ?? [];
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
isPredictionLoading = false;
|
|
|
|
|
@ -75,21 +72,20 @@ class LocationViewModel extends ChangeNotifier {
|
|
|
|
|
|
|
|
|
|
handleGMSMapCameraMoved(GMSMapServices.CameraPosition value) {
|
|
|
|
|
mapCapturedLocation = Location(lat: value.target.latitude, lng: value.target.longitude);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleHMSMapCameraMoved(HMSCameraServices.CameraPosition value) {
|
|
|
|
|
mapCapturedLocation = Location(lat: value.target.lat, lng: value.target.lng);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleOnCameraIdle(){
|
|
|
|
|
if(mapCapturedLocation != null) {
|
|
|
|
|
handleOnCameraIdle() {
|
|
|
|
|
if (mapCapturedLocation != null) {
|
|
|
|
|
getPlaceEncodedData(mapCapturedLocation!.lat, mapCapturedLocation!.lng);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updateSearchQuery(String? value) {
|
|
|
|
|
if(value == null || value.isEmpty){
|
|
|
|
|
if (value == null || value.isEmpty) {
|
|
|
|
|
predictions = [];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
@ -99,18 +95,16 @@ class LocationViewModel extends ChangeNotifier {
|
|
|
|
|
|
|
|
|
|
void flushSearchPredictions() {
|
|
|
|
|
predictions = [];
|
|
|
|
|
mapCapturedLocation= null;
|
|
|
|
|
placeDetails= null;
|
|
|
|
|
geocodeResponse= null;
|
|
|
|
|
selectedPrediction= null;
|
|
|
|
|
mapCapturedLocation = null;
|
|
|
|
|
placeDetails = null;
|
|
|
|
|
geocodeResponse = null;
|
|
|
|
|
selectedPrediction = null;
|
|
|
|
|
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FutureOr<void> selectPlacePrediction(PlacePrediction placePrediction) async{
|
|
|
|
|
selectedPrediction= placePrediction;
|
|
|
|
|
FutureOr<void> selectPlacePrediction(PlacePrediction placePrediction) async {
|
|
|
|
|
selectedPrediction = placePrediction;
|
|
|
|
|
await getPlaceDetails(placePrediction.placeID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|