diff --git a/lib/config/config.dart b/lib/config/config.dart index 37fba8ff..d1a2c22d 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -395,7 +395,7 @@ var UPDATE_COVID_QUESTIONNAIRE = 'Services/Doctors.svc/REST/COVID19_Questionnar var CHANNEL = 3; var GENERAL_ID = 'Cs2020@2016\$2958'; var IP_ADDRESS = '10.20.10.20'; -var VERSION_ID = 8.0; +var VERSION_ID = 8.2; var SETUP_ID = '91877'; var LANGUAGE = 2; var PATIENT_OUT_SA = 0; diff --git a/lib/core/service/client/base_app_client.dart b/lib/core/service/client/base_app_client.dart index dae465ca..a6c13d1c 100644 --- a/lib/core/service/client/base_app_client.dart +++ b/lib/core/service/client/base_app_client.dart @@ -132,7 +132,7 @@ class BaseAppClient { // body['IdentificationNo'] = 2076117163; // body['MobileNo'] = "966503109207"; - // body['PatientID'] = 3628809; //3844083 + // body['PatientID'] = 793807; //3844083 // body['TokenID'] = "@dm!n"; // Patient ID: 3027574 @@ -141,11 +141,11 @@ class BaseAppClient { body.removeWhere((key, value) => key == null || value == null); - // if (BASE_URL == "https://uat.hmgwebservices.com/") { + if (BASE_URL == "https://uat.hmgwebservices.com/") { print("URL : $url"); final jsonBody = json.encode(body); print(jsonBody); - // } + } if (await Utils.checkConnection(bypassConnectionCheck: bypassConnectionCheck)) { final response = await http.post(Uri.parse(url.trim()), body: json.encode(body), headers: headers); diff --git a/lib/models/ambulanceRequest/locationDetails.dart b/lib/models/ambulanceRequest/locationDetails.dart new file mode 100644 index 00000000..2ad61f2d --- /dev/null +++ b/lib/models/ambulanceRequest/locationDetails.dart @@ -0,0 +1,23 @@ +class LocationDetails { + double _lat; + double _long; + String _formattedAddress; + + double get lat => _lat; + + set lat(double lat) { + _lat = lat; + } + + double get long => _long; + + set long(double long) { + _long = long; + } + + String get formattedAddress => _formattedAddress; + + set formattedAddress(String formattedAddress) { + _formattedAddress = formattedAddress; + } +} diff --git a/lib/pages/AlHabibMedicalService/ComprehensiveMedicalCheckup/NewCMC/cmc_location_page.dart b/lib/pages/AlHabibMedicalService/ComprehensiveMedicalCheckup/NewCMC/cmc_location_page.dart index a7478371..0dbc255d 100644 --- a/lib/pages/AlHabibMedicalService/ComprehensiveMedicalCheckup/NewCMC/cmc_location_page.dart +++ b/lib/pages/AlHabibMedicalService/ComprehensiveMedicalCheckup/NewCMC/cmc_location_page.dart @@ -1,18 +1,28 @@ +import 'dart:io'; + import 'package:diplomaticquarterapp/config/config.dart'; +import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; import 'package:diplomaticquarterapp/core/model/ImagesInfo.dart'; import 'package:diplomaticquarterapp/core/viewModels/AlHabibMedicalService/add_new_address_Request_Model.dart'; import 'package:diplomaticquarterapp/core/viewModels/AlHabibMedicalService/cmc_view_model.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/pages/base/base_view.dart'; +import 'package:diplomaticquarterapp/services/permission/permission_service.dart'; import 'package:diplomaticquarterapp/theme/colors.dart'; +import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/uitl/utils.dart'; +import 'package:diplomaticquarterapp/widgets/app_map/google_huawei_map.dart'; +import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart'; import 'package:diplomaticquarterapp/widgets/buttons/secondary_button.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_hms_gms_availability/flutter_hms_gms_availability.dart'; +import 'package:geocoding/geocoding.dart'; +import 'package:geolocator/geolocator.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:google_maps_place_picker/google_maps_place_picker.dart'; import 'package:provider/provider.dart'; @@ -23,7 +33,6 @@ class CMCLocationPage extends StatefulWidget { final double longitude; final dynamic model; - const CMCLocationPage({Key key, this.onPick, this.latitude, this.longitude, this.model}) : super(key: key); @override @@ -35,10 +44,40 @@ class _CMCLocationPageState extends State { double longitude = 0; bool showCurrentLocation = false; Function onPick; + bool isHuawei = false; + Placemark selectedPlace; + AppMap appMap; + static CameraPosition _kGooglePlex = CameraPosition( + target: LatLng(37.42796133580664, -122.085749655962), + zoom: 14.4746, + ); + LatLng currentPostion; + AppSharedPreferences sharedPref = AppSharedPreferences(); @override void initState() { - onPick=widget.onPick; + checkIsHuawei(); + + appMap = AppMap( + _kGooglePlex.toMap(), + onCameraMove: (camera) { + _updatePosition(camera); + }, + onMapCreated: () { + currentPostion = LatLng(widget.latitude, widget.longitude); + latitude = widget.latitude; + longitude = widget.longitude; + _getUserLocation(); + setState(() {}); + }, + onCameraIdle: () async { + List placemarks = await placemarkFromCoordinates(latitude, longitude); + selectedPlace = placemarks[0]; + print(selectedPlace); + }, + ); + + onPick = widget.onPick; latitude = widget.latitude; longitude = widget.longitude; if (latitude == 0.0 && longitude == 0.0) { @@ -47,6 +86,12 @@ class _CMCLocationPageState extends State { super.initState(); } + checkIsHuawei() async { + isHuawei = await FlutterHmsGmsAvailability.isHmsAvailable; + print(isHuawei); + setState(() {}); + } + @override Widget build(BuildContext context) { ProjectViewModel projectViewModel = Provider.of(context); @@ -65,89 +110,194 @@ class _CMCLocationPageState extends State { ImagesInfo(imageAr: 'https://hmgwebservices.com/Images/MobileApp/CMC/ar/0.png', imageEn: 'https://hmgwebservices.com/Images/MobileApp/CMC/en/0.png'), ], appBarTitle: TranslationBase.of(context).addNewAddress, - body: PlacePicker( - apiKey: GOOGLE_API_KEY, - enableMyLocationButton: true, - automaticallyImplyAppBarLeading: false, - autocompleteOnTrailingWhitespace: true, - selectInitialPosition: true, - autocompleteLanguage: projectViewModel.currentLanguage, - enableMapTypeButton: true, - searchForInitialValue: false, - onPlacePicked: (PickResult result) { - print(result.adrAddress); - }, - selectedPlaceWidgetBuilder: (_, selectedPlace, state, isSearchBarFocused) { - print("state: $state, isSearchBarFocused: $isSearchBarFocused"); - - return isSearchBarFocused - ? Container() - : FloatingCard( - bottomPosition: 0.0, - leftPosition: 0.0, - rightPosition: 0.0, - width: 500, - borderRadius: BorderRadius.circular(12.0), - child: state == SearchingState.Searching - ? Center(child: CircularProgressIndicator()) - : Container( - margin: EdgeInsets.all(12), - child: Column( - children: [ - SecondaryButton( - color: CustomColors.accentColor, - textColor: Colors.white, - onTap: () async { - print(selectedPlace); - AddNewAddressRequestModel addNewAddressRequestModel = new AddNewAddressRequestModel( - customer: Customer( - addresses: [ - Addresses( - address1: selectedPlace.formattedAddress, - address2: selectedPlace.formattedAddress, - customerAttributes: "", - city: "", - createdOnUtc: "", - id: "0", - latLong: selectedPlace.geometry.location.lat.toString() + "," + selectedPlace.geometry.location.lng.toString(), - email: "", - ) - ], + body: isHuawei + ? Column( + children: [ + Expanded( + child: Stack( + alignment: Alignment.center, + children: [ + if (appMap != null) appMap, + Container( + margin: EdgeInsets.only(bottom: 50.0), + child: Icon( + Icons.place, + color: CustomColors.accentColor, + size: 50, + ), + ), + ], + ), + ), + Container( + padding: const EdgeInsets.only(left: 20, right: 20, top: 14, bottom: 14), + child: DefaultButton(TranslationBase.of(context).addNewAddress, () async { + AddNewAddressRequestModel addNewAddressRequestModel = new AddNewAddressRequestModel( + customer: Customer(addresses: [ + Addresses( + address1: selectedPlace.street, + address2: selectedPlace.street, + customerAttributes: "", + city: selectedPlace.administrativeArea, + createdOnUtc: "", + id: "0", + faxNumber: "", + phoneNumber: projectViewModel.user.mobileNumber, + province: selectedPlace.administrativeArea, + countryId: 69, + latLong: latitude.toStringAsFixed(6) + "," + longitude.toStringAsFixed(6), + country: selectedPlace.country, + zipPostalCode: selectedPlace.postalCode, + email: projectViewModel.user.emailAddress) + ]), + ); + await model.addAddressInfo(addNewAddressRequestModel: addNewAddressRequestModel); + if (model.state == ViewState.ErrorLocal) { + Utils.showErrorToast(model.error); + } else { + AppToast.showSuccessToast(message: "Address Added Successfully"); + } + Navigator.of(context).pop(addNewAddressRequestModel); + }), + ), + ], + ) + : PlacePicker( + apiKey: GOOGLE_API_KEY, + enableMyLocationButton: true, + automaticallyImplyAppBarLeading: false, + autocompleteOnTrailingWhitespace: true, + selectInitialPosition: true, + autocompleteLanguage: projectViewModel.currentLanguage, + enableMapTypeButton: true, + searchForInitialValue: false, + onPlacePicked: (PickResult result) { + print(result.adrAddress); + }, + selectedPlaceWidgetBuilder: (_, selectedPlace, state, isSearchBarFocused) { + print("state: $state, isSearchBarFocused: $isSearchBarFocused"); + + return isSearchBarFocused + ? Container() + : FloatingCard( + bottomPosition: 0.0, + leftPosition: 0.0, + rightPosition: 0.0, + width: 500, + borderRadius: BorderRadius.circular(12.0), + child: state == SearchingState.Searching + ? Center(child: CircularProgressIndicator()) + : Container( + margin: EdgeInsets.all(12), + child: Column( + children: [ + SecondaryButton( + color: CustomColors.accentColor, + textColor: Colors.white, + onTap: () async { + print(selectedPlace); + AddNewAddressRequestModel addNewAddressRequestModel = new AddNewAddressRequestModel( + customer: Customer( + addresses: [ + Addresses( + address1: selectedPlace.formattedAddress, + address2: selectedPlace.formattedAddress, + customerAttributes: "", + city: "", + createdOnUtc: "", + id: "0", + latLong: selectedPlace.geometry.location.lat.toString() + "," + selectedPlace.geometry.location.lng.toString(), + email: "", + ) + ], + ), + ); + + selectedPlace.addressComponents.forEach((e) { + if (e.types.contains("country")) { + addNewAddressRequestModel.customer.addresses[0].country = e.longName; + } + if (e.types.contains("postal_code")) { + addNewAddressRequestModel.customer.addresses[0].zipPostalCode = e.longName; + } + if (e.types.contains("locality")) { + addNewAddressRequestModel.customer.addresses[0].city = e.longName; + } + }); + + await model.addAddressInfo(addNewAddressRequestModel: addNewAddressRequestModel); + if (model.state == ViewState.ErrorLocal) { + Utils.showErrorToast(model.error); + } else { + onPick(); + AppToast.showSuccessToast(message: "Address Added Successfully"); + } + Navigator.of(context).pop(); + }, + label: TranslationBase.of(context).addNewAddress, ), - ); - - selectedPlace.addressComponents.forEach((e) { - if (e.types.contains("country")) { - addNewAddressRequestModel.customer.addresses[0].country = e.longName; - } - if (e.types.contains("postal_code")) { - addNewAddressRequestModel.customer.addresses[0].zipPostalCode = e.longName; - } - if (e.types.contains("locality")) { - addNewAddressRequestModel.customer.addresses[0].city = e.longName; - } - }); - - await model.addAddressInfo(addNewAddressRequestModel: addNewAddressRequestModel); - if (model.state == ViewState.ErrorLocal) { - Utils.showErrorToast(model.error); - } else { - onPick(); - AppToast.showSuccessToast(message: "Address Added Successfully"); - } - Navigator.of(context).pop(); - }, - label: TranslationBase.of(context).addNewAddress, + ], + ), ), - ], - ), - ), - ); - }, - initialPosition: LatLng(latitude, longitude), - useCurrentLocation: showCurrentLocation, - ), + ); + }, + initialPosition: LatLng(latitude, longitude), + useCurrentLocation: showCurrentLocation, + ), ), ); } + + void _getUserLocation() async { + if (await this.sharedPref.getDouble(USER_LAT) != null && await this.sharedPref.getDouble(USER_LONG) != null) { + var lat = await this.sharedPref.getDouble(USER_LAT); + var long = await this.sharedPref.getDouble(USER_LONG); + latitude = lat; + longitude = long; + currentPostion = LatLng(lat, long); + setMap(); + } else { + if (await PermissionService.isLocationEnabled()) { + Geolocator.getLastKnownPosition().then((value) { + latitude = value.latitude; + longitude = value.longitude; + currentPostion = LatLng(latitude, longitude); + setMap(); + }); + } else { + if (Platform.isAndroid) { + Utils.showPermissionConsentDialog(context, TranslationBase.of(context).locationPermissionDialog, () { + Geolocator.getLastKnownPosition().then((value) { + latitude = value.latitude; + longitude = value.longitude; + currentPostion = LatLng(latitude, longitude); + setMap(); + }); + }); + } else { + Geolocator.getLastKnownPosition().then((value) { + latitude = value.latitude; + longitude = value.longitude; + setMap(); + }); + } + } + } + } + + setMap() { + setState(() { + _kGooglePlex = CameraPosition( + target: currentPostion, + zoom: 14.4746, + ); + appMap.moveTo(cameraPostion: _kGooglePlex); + }); + } + + void _updatePosition(CameraPosition _position) { + print(_position); + latitude = _position.target.latitude; + longitude = _position.target.longitude; + } } diff --git a/lib/pages/AlHabibMedicalService/HomeHealthCare/NewHomeHealthCare/location_page.dart b/lib/pages/AlHabibMedicalService/HomeHealthCare/NewHomeHealthCare/location_page.dart index ee039d47..81f2d03f 100644 --- a/lib/pages/AlHabibMedicalService/HomeHealthCare/NewHomeHealthCare/location_page.dart +++ b/lib/pages/AlHabibMedicalService/HomeHealthCare/NewHomeHealthCare/location_page.dart @@ -1,4 +1,3 @@ -import 'dart:async'; import 'dart:io'; import 'package:diplomaticquarterapp/config/config.dart'; @@ -9,6 +8,7 @@ import 'package:diplomaticquarterapp/core/viewModels/AlHabibMedicalService/home_ import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/pages/base/base_view.dart'; import 'package:diplomaticquarterapp/services/permission/permission_service.dart'; +import 'package:diplomaticquarterapp/theme/colors.dart'; import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; @@ -18,6 +18,7 @@ import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_hms_gms_availability/flutter_hms_gms_availability.dart'; import 'package:geocoding/geocoding.dart'; import 'package:geolocator/geolocator.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; @@ -43,6 +44,8 @@ class _LocationPageState extends State { GoogleMapController mapController; + bool isHuawei = false; + AppMap appMap; AppSharedPreferences sharedPref = AppSharedPreferences(); static CameraPosition _kGooglePlex = CameraPosition( @@ -50,6 +53,7 @@ class _LocationPageState extends State { zoom: 14.4746, ); LatLng currentPostion; + // Completer mapController = Completer(); Placemark selectedPlace; @@ -57,6 +61,7 @@ class _LocationPageState extends State { void initState() { latitude = widget.latitude; longitude = widget.longitude; + checkIsHuawei(); if (latitude == 0.0 && longitude == 0.0) { showCurrentLocation = true; } @@ -70,12 +75,12 @@ class _LocationPageState extends State { latitude = widget.latitude; longitude = widget.longitude; _getUserLocation(); - // setMap(); setState(() {}); }, onCameraIdle: () async { List placemarks = await placemarkFromCoordinates(latitude, longitude); selectedPlace = placemarks[0]; + print(selectedPlace); }, ); super.initState(); @@ -93,213 +98,136 @@ class _LocationPageState extends State { baseViewModel: model, showNewAppBarTitle: true, showNewAppBar: true, - body: - // Column( - // children: [ - // Expanded( - // child: Stack( - // alignment: Alignment.center, - // children: [ - // if (appMap != null) appMap, - // Container( - // margin: EdgeInsets.only(bottom: 50.0), - // child: Icon( - // Icons.place, - // color: CustomColors.accentColor, - // size: 50, - // ), - // ), - // ], - // ), - // ), - // Container( - // padding: const EdgeInsets.only(left: 20, right: 20, top: 14, bottom: 14), - // child: DefaultButton(TranslationBase.of(context).addNewAddress, () async { - // AddNewAddressRequestModel addNewAddressRequestModel = new AddNewAddressRequestModel( - // customer: Customer(addresses: [ - // Addresses( - // address1: selectedPlace.name, - // address2: selectedPlace.street, - // customerAttributes: "", - // city: selectedPlace.locality, - // createdOnUtc: "", - // id: "0", - // faxNumber: "", - // phoneNumber: projectViewModel.user.mobileNumber, - // province: selectedPlace.locality, - // countryId: 69, - // latLong: "$latitude,$longitude", - // country: selectedPlace.country, - // zipPostalCode: selectedPlace.postalCode, - // email: projectViewModel.user.emailAddress) - // ]), - // ); - // await model.addAddressInfo(addNewAddressRequestModel: addNewAddressRequestModel); - // if (model.state == ViewState.ErrorLocal) { - // Utils.showErrorToast(model.error); - // } else { - // AppToast.showSuccessToast(message: "Address Added Successfully"); - // } - // Navigator.of(context).pop(addNewAddressRequestModel); - // }), - // ), - // ], - // ), - - PlacePicker( - apiKey: GOOGLE_API_KEY, - enableMyLocationButton: true, - automaticallyImplyAppBarLeading: false, - autocompleteOnTrailingWhitespace: true, - selectInitialPosition: true, - autocompleteLanguage: projectViewModel.currentLanguage, - enableMapTypeButton: true, - searchForInitialValue: false, - onMapCreated: (GoogleMapController controller) { - mapController = controller; - }, - onPlacePicked: (PickResult result) { - print(result.adrAddress); - }, - selectedPlaceWidgetBuilder: (_, selectedPlace, state, isSearchBarFocused) { - print("state: $state, isSearchBarFocused: $isSearchBarFocused"); - return isSearchBarFocused - ? Container() - : FloatingCard( - bottomPosition: 0.0, - leftPosition: 0.0, - rightPosition: 0.0, - width: 500, - borderRadius: BorderRadius.circular(0.0), - child: state == SearchingState.Searching - ? SizedBox(height: 43, child: Center(child: CircularProgressIndicator())).insideContainer - : DefaultButton(TranslationBase.of(context).addNewAddress, () async { - AddNewAddressRequestModel addNewAddressRequestModel = new AddNewAddressRequestModel( - customer: Customer(addresses: [ - Addresses( - address1: selectedPlace.formattedAddress, - address2: selectedPlace.formattedAddress, - customerAttributes: "", - createdOnUtc: "", - id: "0", - faxNumber: "", - phoneNumber: projectViewModel.user.mobileNumber, - countryId: 69, - latLong: selectedPlace.geometry.location.lat.toString() + "," + selectedPlace.geometry.location.lng.toString(), - email: projectViewModel.user.emailAddress) - // Addresses( - // address1: selectedPlace.formattedAddress, - // address2: selectedPlace.formattedAddress, - // customerAttributes: "", - // city: "", - // createdOnUtc: "", - // id: "0", - // latLong: "${selectedPlace.geometry.location}", - // email: "") - ]), - ); + body: isHuawei + ? Column( + children: [ + Expanded( + child: Stack( + alignment: Alignment.center, + children: [ + if (appMap != null) appMap, + Container( + margin: EdgeInsets.only(bottom: 50.0), + child: Icon( + Icons.place, + color: CustomColors.accentColor, + size: 50, + ), + ), + ], + ), + ), + Container( + padding: const EdgeInsets.only(left: 20, right: 20, top: 14, bottom: 14), + child: DefaultButton(TranslationBase.of(context).addNewAddress, () async { + AddNewAddressRequestModel addNewAddressRequestModel = new AddNewAddressRequestModel( + customer: Customer(addresses: [ + Addresses( + address1: selectedPlace.street, + address2: selectedPlace.street, + customerAttributes: "", + city: selectedPlace.administrativeArea, + createdOnUtc: "", + id: "0", + faxNumber: "", + phoneNumber: projectViewModel.user.mobileNumber, + province: selectedPlace.administrativeArea, + countryId: 69, + latLong: latitude.toStringAsFixed(6) + "," + longitude.toStringAsFixed(6), + country: selectedPlace.country, + zipPostalCode: selectedPlace.postalCode, + email: projectViewModel.user.emailAddress) + ]), + ); + await model.addAddressInfo(addNewAddressRequestModel: addNewAddressRequestModel); + if (model.state == ViewState.ErrorLocal) { + Utils.showErrorToast(model.error); + } else { + AppToast.showSuccessToast(message: "Address Added Successfully"); + } + Navigator.of(context).pop(addNewAddressRequestModel); + }), + ), + ], + ) + : PlacePicker( + apiKey: GOOGLE_API_KEY, + enableMyLocationButton: true, + automaticallyImplyAppBarLeading: false, + autocompleteOnTrailingWhitespace: true, + selectInitialPosition: true, + autocompleteLanguage: projectViewModel.currentLanguage, + enableMapTypeButton: true, + searchForInitialValue: false, + onMapCreated: (GoogleMapController controller) { + mapController = controller; + }, + onPlacePicked: (PickResult result) { + print(result.adrAddress); + }, + selectedPlaceWidgetBuilder: (_, selectedPlace, state, isSearchBarFocused) { + print("state: $state, isSearchBarFocused: $isSearchBarFocused"); + return isSearchBarFocused + ? Container() + : FloatingCard( + bottomPosition: 0.0, + leftPosition: 0.0, + rightPosition: 0.0, + width: 500, + borderRadius: BorderRadius.circular(0.0), + child: state == SearchingState.Searching + ? SizedBox(height: 43, child: Center(child: CircularProgressIndicator())).insideContainer + : DefaultButton(TranslationBase.of(context).addNewAddress, () async { + AddNewAddressRequestModel addNewAddressRequestModel = new AddNewAddressRequestModel( + customer: Customer(addresses: [ + Addresses( + address1: selectedPlace.formattedAddress, + address2: selectedPlace.formattedAddress, + customerAttributes: "", + createdOnUtc: "", + id: "0", + faxNumber: "", + phoneNumber: projectViewModel.user.mobileNumber, + countryId: 69, + latLong: selectedPlace.geometry.location.lat.toString() + "," + selectedPlace.geometry.location.lng.toString(), + email: projectViewModel.user.emailAddress) + ]), + ); - selectedPlace.addressComponents.forEach((e) { - if (e.types.contains("country")) { - addNewAddressRequestModel.customer.addresses[0].country = e.longName; - } - if (e.types.contains("postal_code")) { - addNewAddressRequestModel.customer.addresses[0].zipPostalCode = e.longName; - } - if (e.types.contains("locality")) { - addNewAddressRequestModel.customer.addresses[0].city = e.longName; - } - }); + selectedPlace.addressComponents.forEach((e) { + if (e.types.contains("country")) { + addNewAddressRequestModel.customer.addresses[0].country = e.longName; + } + if (e.types.contains("postal_code")) { + addNewAddressRequestModel.customer.addresses[0].zipPostalCode = e.longName; + } + if (e.types.contains("locality")) { + addNewAddressRequestModel.customer.addresses[0].city = e.longName; + } + }); - await model.addAddressInfo(addNewAddressRequestModel: addNewAddressRequestModel); - if (model.state == ViewState.ErrorLocal) { - Utils.showErrorToast(model.error); - } else { - AppToast.showSuccessToast(message: "Address Added Successfully"); - } - Navigator.of(context).pop(addNewAddressRequestModel); - }).insideContainer); - }, - initialPosition: LatLng(latitude, longitude), - useCurrentLocation: showCurrentLocation, - ), - - // Expanded( - // child: Stack( - // alignment: Alignment.center, - // children: [ - // if (appMap != null) appMap, - // Container( - // margin: EdgeInsets.only(bottom: 50.0), - // child: Icon( - // Icons.place, - // color: CustomColors.accentColor, - // size: 50, - // ), - // ), - // // FloatingCard( - // // bottomPosition: 0.0, - // // leftPosition: 0.0, - // // rightPosition: 0.0, - // // width: 500, - // // borderRadius: BorderRadius.circular(0.0), - // // // child: state == SearchingState.Searching - // // // ? SizedBox(height: 43, child: Center(child: CircularProgressIndicator())).insideContainer - // // // : - // // child: DefaultButton(TranslationBase.of(context).addNewAddress, () async { - // // AddNewAddressRequestModel addNewAddressRequestModel = new AddNewAddressRequestModel( - // // customer: Customer(addresses: [ - // // // Addresses( - // // // address1: selectedPlace.formattedAddress, - // // // address2: selectedPlace.formattedAddress, - // // // customerAttributes: "", - // // // createdOnUtc: "", - // // // id: "0", - // // // faxNumber: "", - // // // phoneNumber: projectViewModel.user.mobileNumber, - // // // countryId: 69, - // // // latLong: "$latitude,$longitude", - // // // email: projectViewModel.user.emailAddress) - // // - // // // Addresses( - // // // address1: selectedPlace.formattedAddress, - // // // address2: selectedPlace.formattedAddress, - // // // customerAttributes: "", - // // // city: "", - // // // createdOnUtc: "", - // // // id: "0", - // // // latLong: "${selectedPlace.geometry.location}", - // // // email: "") - // // ]), - // // ); - // // - // // // selectedPlace.addressComponents.forEach((e) { - // // // if (e.types.contains("country")) { - // // // addNewAddressRequestModel.customer.addresses[0].country = e.longName; - // // // } - // // // if (e.types.contains("postal_code")) { - // // // addNewAddressRequestModel.customer.addresses[0].zipPostalCode = e.longName; - // // // } - // // // if (e.types.contains("locality")) { - // // // addNewAddressRequestModel.customer.addresses[0].city = e.longName; - // // // } - // // // }); - // // - // // await model.addAddressInfo(addNewAddressRequestModel: addNewAddressRequestModel); - // // if (model.state == ViewState.ErrorLocal) { - // // Utils.showErrorToast(model.error); - // // } else { - // // AppToast.showSuccessToast(message: "Address Added Successfully"); - // // } - // // Navigator.of(context).pop(addNewAddressRequestModel); - // // }).insideContainer), - // ], - // ), - // ), + await model.addAddressInfo(addNewAddressRequestModel: addNewAddressRequestModel); + if (model.state == ViewState.ErrorLocal) { + Utils.showErrorToast(model.error); + } else { + AppToast.showSuccessToast(message: "Address Added Successfully"); + } + Navigator.of(context).pop(addNewAddressRequestModel); + }).insideContainer); + }, + initialPosition: LatLng(latitude, longitude), + useCurrentLocation: showCurrentLocation, + ), ), ); } + checkIsHuawei() async { + isHuawei = await FlutterHmsGmsAvailability.isHmsAvailable; + print(isHuawei); + setState(() {}); + } + void _getUserLocation() async { if (await this.sharedPref.getDouble(USER_LAT) != null && await this.sharedPref.getDouble(USER_LONG) != null) { var lat = await this.sharedPref.getDouble(USER_LAT); diff --git a/lib/pages/AlHabibMedicalService/HomeHealthCare/NewHomeHealthCare/new_Home_health_care_step_tow_page.dart b/lib/pages/AlHabibMedicalService/HomeHealthCare/NewHomeHealthCare/new_Home_health_care_step_tow_page.dart index 0c59f10e..d771f2b5 100644 --- a/lib/pages/AlHabibMedicalService/HomeHealthCare/NewHomeHealthCare/new_Home_health_care_step_tow_page.dart +++ b/lib/pages/AlHabibMedicalService/HomeHealthCare/NewHomeHealthCare/new_Home_health_care_step_tow_page.dart @@ -66,6 +66,9 @@ class _NewHomeHealthCareStepTowPageState extends State _updatePosition(_position)), - // onMapCreated: (GoogleMapController controller) { - // googleMapController = controller; - // _controller.complete(controller); - // }, - // ), - // Icon( - // Icons.place, - // color: CustomColors.accentColor, - // size: 50, - // ), - // ], - // ), - // ), Expanded( child: Stack( alignment: Alignment.center, diff --git a/lib/pages/BookAppointment/BookConfirm.dart b/lib/pages/BookAppointment/BookConfirm.dart index 3a8d0a5a..706a51d9 100644 --- a/lib/pages/BookAppointment/BookConfirm.dart +++ b/lib/pages/BookAppointment/BookConfirm.dart @@ -245,18 +245,19 @@ class _BookConfirmState extends State { ); } - cancelAppointment(DoctorList docObject, AppoitmentAllHistoryResultList appo, BuildContext context) { + cancelAppointment(DoctorList docObject, AppoitmentAllHistoryResultList appo, BuildContext context) async { ConfirmDialog.closeAlertDialog(context); GifLoaderDialogUtils.showMyDialog(context); DoctorsListService service = new DoctorsListService(); + bool isLiveCareSchedule = await this.sharedPref.getBool(IS_LIVECARE_APPOINTMENT); service.cancelAppointment(appo, context).then((res) { GifLoaderDialogUtils.hideDialog(context); if (res['MessageStatus'] == 1) { Future.delayed(new Duration(milliseconds: 1500), () async { - if (await this.sharedPref.getBool(IS_LIVECARE_APPOINTMENT) != null && !await this.sharedPref.getBool(IS_LIVECARE_APPOINTMENT)) { - insertAppointment(context, widget.doctor, widget.initialSlotDuration); - } else { + if (isLiveCareSchedule != null && isLiveCareSchedule) { insertLiveCareScheduledAppointment(context, widget.doctor); + } else { + insertAppointment(context, widget.doctor, widget.initialSlotDuration); } }); } else { diff --git a/lib/pages/BookAppointment/components/DocAvailableAppointments.dart b/lib/pages/BookAppointment/components/DocAvailableAppointments.dart index 8a2ccc8d..01f425cf 100644 --- a/lib/pages/BookAppointment/components/DocAvailableAppointments.dart +++ b/lib/pages/BookAppointment/components/DocAvailableAppointments.dart @@ -230,10 +230,16 @@ class _DocAvailableAppointmentsState extends State wit Map _eventsParsed; List slotsList = []; DateTime date; + // print("TIMEZONE"); + // print(DateTime.now().timeZoneName); final DateFormat formatter = DateFormat('HH:mm'); final DateFormat dateFormatter = DateFormat('yyyy-MM-dd'); for (var i = 0; i < freeSlotsResponse.length; i++) { - date = Jiffy(DateUtil.convertStringToDate(freeSlotsResponse[i])).add(hours: 3).dateTime; + if ((widget.doctor.projectID == 2 && DateTime.now().timeZoneName == "+04") || widget.doctor.projectID == 3 && DateTime.now().timeZoneName == "+04") { + date = Jiffy(DateUtil.convertStringToDate(freeSlotsResponse[i])).subtract(hours: 1).dateTime; + } else { + date = DateUtil.convertStringToDate(freeSlotsResponse[i]); + } slotsList.add(FreeSlot(date, ['slot'])); docFreeSlots.add(TimeSlot(isoTime: formatter.format(date), start: new DateTime(date.year, date.month, date.day, 0, 0, 0, 0), end: date)); } diff --git a/lib/pages/ErService/AmbulanceRequestIndexPages/PickupLocation.dart b/lib/pages/ErService/AmbulanceRequestIndexPages/PickupLocation.dart index 67d2f979..34340e0c 100644 --- a/lib/pages/ErService/AmbulanceRequestIndexPages/PickupLocation.dart +++ b/lib/pages/ErService/AmbulanceRequestIndexPages/PickupLocation.dart @@ -4,6 +4,7 @@ import 'package:diplomaticquarterapp/core/model/er/PatientER_RC.dart'; import 'package:diplomaticquarterapp/core/model/hospitals/hospitals_model.dart'; import 'package:diplomaticquarterapp/core/viewModels/er/am_request_view_model.dart'; import 'package:diplomaticquarterapp/models/Appointments/AppoimentAllHistoryResultList.dart'; +import 'package:diplomaticquarterapp/models/ambulanceRequest/locationDetails.dart'; import 'package:diplomaticquarterapp/pages/ErService/widgets/AppointmentCard.dart'; import 'package:diplomaticquarterapp/uitl/ProgressDialog.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart'; @@ -11,7 +12,6 @@ import 'package:diplomaticquarterapp/uitl/date_uitl.dart'; import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart'; -import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; import 'package:diplomaticquarterapp/widgets/dialogs/radio_selection_dialog.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; import 'package:diplomaticquarterapp/widgets/pickupLocation/PickupLocationFromMap.dart'; @@ -19,7 +19,6 @@ import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:geolocator/geolocator.dart'; -import 'package:google_maps_place_picker/google_maps_place_picker.dart'; import '../AvailableAppointmentsPage.dart'; @@ -44,7 +43,7 @@ class _PickupLocationState extends State { double _longitude; AppoitmentAllHistoryResultList myAppointment; HospitalsModel _selectedHospital; - PickResult _result; + LocationDetails _result; @override void initState() { @@ -496,15 +495,15 @@ class _PickupLocationState extends State { setState(() { widget.patientER_RC.transportationDetails.pickupSpot = _isInsideHome ? 1 : 0; if (widget.patientER_RC.transportationDetails.direction == 0) { - widget.patientER_RC.transportationDetails.dropoffLatitude = _result.geometry.location.lat.toString(); - widget.patientER_RC.transportationDetails.dropoffLongitude = _result.geometry.location.lng.toString(); + widget.patientER_RC.transportationDetails.dropoffLatitude = _result.lat.toStringAsFixed(6); + widget.patientER_RC.transportationDetails.dropoffLongitude = _result.long.toStringAsFixed(6); widget.patientER_RC.transportationDetails.pickupLatitude = _selectedHospital.latitude; widget.patientER_RC.transportationDetails.pickupLongitude = _selectedHospital.longitude; } else { widget.patientER_RC.transportationDetails.pickupLatitude = _selectedHospital.latitude; widget.patientER_RC.transportationDetails.pickupLongitude = _selectedHospital.longitude; - widget.patientER_RC.transportationDetails.dropoffLatitude = _result.geometry.location.lat.toString(); - widget.patientER_RC.transportationDetails.dropoffLongitude = _result.geometry.location.lng.toString(); + widget.patientER_RC.transportationDetails.dropoffLatitude = _result.lat.toStringAsFixed(6); + widget.patientER_RC.transportationDetails.dropoffLongitude = _result.long.toStringAsFixed(6); } // widget.patientER.latitude = diff --git a/lib/pages/ToDoList/ToDo.dart b/lib/pages/ToDoList/ToDo.dart index 0c71a2ea..5dacf8db 100644 --- a/lib/pages/ToDoList/ToDo.dart +++ b/lib/pages/ToDoList/ToDo.dart @@ -247,7 +247,7 @@ class _ToDoState extends State with SingleTickerProviderStateMixin { children: [ MyRichText(TranslationBase.of(context).clinic + ": ", widget.appoList[index].clinicName, projectViewModel.isArabic), MyRichText(TranslationBase.of(context).appointmentDate + ": ", - DateUtil.getDayMonthYearHourMinuteDateFormatted(DateUtil.convertStringToDate(widget.appoList[index].appointmentDate)), projectViewModel.isArabic), + DateUtil.getDayMonthYearDateFormatted(DateUtil.convertStringToDate(widget.appoList[index].appointmentDate)) + " " + widget.appoList[index].startTime.substring(0, 5), projectViewModel.isArabic), MyRichText(TranslationBase.of(context).branch, widget.appoList[index].projectName, projectViewModel.isArabic), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, diff --git a/lib/pages/ToDoList/payment_method_select.dart b/lib/pages/ToDoList/payment_method_select.dart index a2e791f0..e389830a 100644 --- a/lib/pages/ToDoList/payment_method_select.dart +++ b/lib/pages/ToDoList/payment_method_select.dart @@ -198,6 +198,7 @@ class _PaymentMethodState extends State { ), ), ), + // if (projectViewModel.havePrivilege(90)) // Container( // width: double.infinity, // child: InkWell( diff --git a/lib/pages/landing/landing_page.dart b/lib/pages/landing/landing_page.dart index 68e47948..815bab34 100644 --- a/lib/pages/landing/landing_page.dart +++ b/lib/pages/landing/landing_page.dart @@ -283,7 +283,7 @@ class _LandingPageState extends State with WidgetsBindingObserver { super.initState(); PushNotificationHandler.getInstance().onResume(); - // VoIP Callbacks + // // VoIP Callbacks // voIPKit.getVoIPToken().then((value) { // print('🎈 example: getVoIPToken: $value'); // sharedPref.setString("VOIPToken", value); diff --git a/lib/pages/webRTC/OpenTok/OpenTok.dart b/lib/pages/webRTC/OpenTok/OpenTok.dart index 4246049d..6c70170f 100644 --- a/lib/pages/webRTC/OpenTok/OpenTok.dart +++ b/lib/pages/webRTC/OpenTok/OpenTok.dart @@ -10,6 +10,7 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; +import 'package:flutter_ios_voip_kit/flutter_ios_voip_kit.dart'; import 'OpenTokPlatformBridge.dart'; @@ -36,6 +37,7 @@ class OpenTokState extends State{ var audioMute = false; var videoMute = false; + final voIPKit = FlutterIOSVoIPKit.instance; initOpenTok(){ openTokPlatform = OpenTokPlatformBridge.init( @@ -196,6 +198,7 @@ class OpenTokState extends State{ Future _onHangup() async { print('onHangup'); await openTokPlatform.hangupCall(); + voIPKit.endCall(); endCallAPI(); Navigator.of(context).pop(); } diff --git a/lib/uitl/date_uitl.dart b/lib/uitl/date_uitl.dart index 8cdbeffb..7b0dfcaa 100644 --- a/lib/uitl/date_uitl.dart +++ b/lib/uitl/date_uitl.dart @@ -5,16 +5,15 @@ class DateUtil { /// convert String To Date function /// [date] String we want to convert static DateTime convertStringToDate(String date) { - // /Date(1585774800000+0300)/ if (date != null) { const start = "/Date("; - const end = "+0300)"; + const end = "+0300)/"; final startIndex = date.indexOf(start); final endIndex = date.indexOf(end, startIndex + start.length); return DateTime.fromMillisecondsSinceEpoch( int.parse( date.substring(startIndex + start.length, endIndex), - ), isUtc: true + ) ); } else return DateTime.now(); diff --git a/lib/uitl/push-notification-handler.dart b/lib/uitl/push-notification-handler.dart index 3eadea1f..7d31f484 100644 --- a/lib/uitl/push-notification-handler.dart +++ b/lib/uitl/push-notification-handler.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:convert'; import 'dart:io'; @@ -8,12 +9,16 @@ import 'package:diplomaticquarterapp/models/LiveCare/IncomingCallData.dart'; import 'package:diplomaticquarterapp/pages/DrawerPages/notifications/notification_details_page.dart'; import 'package:diplomaticquarterapp/pages/landing/landing_page.dart'; import 'package:diplomaticquarterapp/pages/livecare/incoming_call.dart'; +import 'package:diplomaticquarterapp/pages/webRTC/OpenTok/OpenTok.dart'; import 'package:diplomaticquarterapp/uitl/app-permissions.dart'; import 'package:diplomaticquarterapp/uitl/date_uitl.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:firebase_messaging/firebase_messaging.dart' as fir; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_hms_gms_availability/flutter_hms_gms_availability.dart'; +import 'package:flutter_ios_voip_kit/call_state_type.dart'; +import 'package:flutter_ios_voip_kit/flutter_ios_voip_kit.dart'; import 'package:huawei_push/huawei_push.dart' as h_push; import 'app_shared_preferences.dart'; @@ -80,6 +85,10 @@ RemoteMessage toFirebaseRemoteMessage(h_push.RemoteMessage message) { return fire_message; } +callPage(String sessionID, String token) async { + await NavigationService.navigateToPage(OpenTokConnectCallPage(apiKey: OPENTOK_API_KEY, sessionId: sessionID, token: token)); +} + _incomingCall(Map data) async { LandingPage.incomingCallData = IncomingCallData.fromJson(data); if (LandingPage.isOpenCallPage == false) { @@ -95,6 +104,30 @@ _incomingCall(Map data) async { class PushNotificationHandler { final BuildContext context; static PushNotificationHandler _instance; + final voIPKit = FlutterIOSVoIPKit.instance; + + Timer timeOutTimer; + bool isTalking = false; + + var data = { + "AppointmentNo": "2016059247", + "ProjectID": "15", + "NotificationType": "10", + "background": "0", + "doctorname": "Call from postman", + "clinicname": "LIVECARE FAMILY MEDICINE AND GP", + "speciality": "General Practioner", + "appointmentdate": "2022-01-19", + "appointmenttime": "12:10", + "PatientName": "Testing", + "session_id": "1_MX40NjIwOTk2Mn5-MTY1NDE2NDQxMjc2Mn5xc3NCZkNIejJOdzgzTkg2TmlXblhQdnl-fg", + "token": + "T1==cGFydG5lcl9pZD00NjIwOTk2MiZzaWc9MTliNTA3NDAxYmU0MjI5OGY5NTcxZTdhNzQyMTcyZjRjMjBhNjljZTpzZXNzaW9uX2lkPTFfTVg0ME5qSXdPVGsyTW41LU1UWTFOREUyTkRReE1qYzJNbjV4YzNOQ1prTkllakpPZHpnelRrZzJUbWxYYmxoUWRubC1mZyZjcmVhdGVfdGltZT0xNjU0MTY0NDEzJm5vbmNlPTAuNjM3ODkzNDk4NDQ2NTIxOSZyb2xlPW1vZGVyYXRvciZleHBpcmVfdGltZT0xNjU0MjUwODEzJmluaXRpYWxfbGF5b3V0X2NsYXNzX2xpc3Q9", + "DoctorImageURL": "https://image.shutterstock.com/image-vector/sample-stamp-square-grunge-sign-260nw-1474408826.jpg", + "callerID": "9920", + "PatientID": "1231755", + "is_call": "true" + }; PushNotificationHandler(this.context) { PushNotificationHandler._instance = this; @@ -102,80 +135,162 @@ class PushNotificationHandler { static PushNotificationHandler getInstance() => _instance; - init() async { - final fcmToken = await FirebaseMessaging.instance.getToken(); - if (fcmToken != null) onToken(fcmToken); - if (Platform.isIOS) { - final permission = await FirebaseMessaging.instance.requestPermission(); - if (permission.authorizationStatus == AuthorizationStatus.denied) return; - } + void _timeOut({ + int seconds = 15, + }) async { + timeOutTimer = Timer(Duration(seconds: seconds), () async { + print('🎈 example: timeOut'); + final incomingCallerName = await voIPKit.getIncomingCallerName(); + voIPKit.unansweredIncomingCall( + skipLocalNotification: false, + missedCallTitle: '📞 Missed call', + missedCallBody: 'There was a call from $incomingCallerName', + ); + }); + } - // if (Platform.isAndroid && (await FlutterHmsGmsAvailability.isHmsAvailable)) { - // // 'Android HMS' (Handle Huawei Push_Kit Streams) + init() async { + // VoIP Callbacks + // voIPKit.getVoIPToken().then((value) { + // print('🎈 example: getVoIPToken: $value'); + // // sharedPref.setString("VOIPToken", value); + // }); // - // h_push.Push.enableLogger(); - // final result = await h_push.Push.setAutoInitEnabled(true); + // voIPKit.onDidReceiveIncomingPush = ( + // Map payload, + // ) async { + // print('🎈 example: onDidReceiveIncomingPush $payload'); + // _timeOut(); + // }; // - // h_push.Push.onNotificationOpenedApp.listen((message) { - // newMessage(toFirebaseRemoteMessage(message)); - // }, onError: (e) => print(e.toString())); + // voIPKit.onDidRejectIncomingCall = ( + // String uuid, + // String callerId, + // ) { + // if (isTalking) { + // return; + // } // - // h_push.Push.onMessageReceivedStream.listen((message) { - // newMessage(toFirebaseRemoteMessage(message)); - // }, onError: (e) => print(e.toString())); + // print('🎈 example: onDidRejectIncomingCall $uuid, $callerId'); + // voIPKit.endCall(); + // timeOutTimer?.cancel(); // - // h_push.Push.getTokenStream.listen((token) { - // onToken(token); - // }, onError: (e) => print(e.toString())); - // await h_push.Push.getToken(''); + // // setState(() { + // // isTalking = false; + // // }); + // }; // - // h_push.Push.registerBackgroundMessageHandler(backgroundMessageHandler); - // } else { - // 'Android GMS or iOS' (Handle Firebase Messaging Streams - - FirebaseMessaging.instance.getInitialMessage().then((RemoteMessage message) async { - print("Firebase getInitialMessage!!!"); - // Utils.showPermissionConsentDialog(context, "getInitialMessage", (){}); - if (Platform.isIOS) - await Future.delayed(Duration(milliseconds: 3000)).then((value) { - if(message != null) - newMessage(message); - }); - else - // if(message != null) - newMessage(message); - }); + // voIPKit.onDidAcceptIncomingCall = ( + // String uuid, + // String callerId, + // ) { + // // print('🎈 example: isTalking $isTalking'); + // // if (isTalking) { + // // return; + // // } + // + // print('🎈 example: onDidAcceptIncomingCall $uuid, $callerId'); + // + // String sessionID = callerId.split("*")[0]; + // String token = callerId.split("*")[1]; + // + // print("🎈 SessionID: $sessionID"); + // print("🎈 Token: $token"); + // + // voIPKit.acceptIncomingCall(callerState: CallStateType.calling); + // voIPKit.callConnected(); + // timeOutTimer?.cancel(); + // + // print("🎈 CALL ACCEPTED!!!"); + // + // Future.delayed(new Duration(milliseconds: 1000)).then((value) async { + // print("🎈 Incoming Call!!!"); + // callPage(sessionID, token); + // }); + // + // // print("🎈 Identity: $identity"); + // // print("🎈 Name: $name"); + // + // // setState(() { + // // isTalking = true; + // // }); + // }; - FirebaseMessaging.onMessage.listen((RemoteMessage message) async { - print("Firebase onMessage!!!"); - // Utils.showPermissionConsentDialog(context, "onMessage", (){}); - // newMessage(message); - if (Platform.isIOS) - await Future.delayed(Duration(milliseconds: 3000)).then((value) { + if (Platform.isAndroid && (!await FlutterHmsGmsAvailability.isHmsAvailable)) { + final fcmToken = await FirebaseMessaging.instance.getToken(); + if (fcmToken != null) onToken(fcmToken); + } + + if (Platform.isIOS) { + final permission = await FirebaseMessaging.instance.requestPermission(); + if (permission.authorizationStatus == AuthorizationStatus.denied) return; + } + + if (Platform.isAndroid && (await FlutterHmsGmsAvailability.isHmsAvailable)) { + // 'Android HMS' (Handle Huawei Push_Kit Streams) + + h_push.Push.enableLogger(); + final result = await h_push.Push.setAutoInitEnabled(true); + + h_push.Push.onNotificationOpenedApp.listen((message) { + newMessage(toFirebaseRemoteMessage(message)); + }, onError: (e) => print(e.toString())); + + h_push.Push.onMessageReceivedStream.listen((message) { + newMessage(toFirebaseRemoteMessage(message)); + }, onError: (e) => print(e.toString())); + + h_push.Push.getTokenStream.listen((token) { + onToken(token); + }, onError: (e) => print(e.toString())); + await h_push.Push.getToken(''); + + h_push.Push.registerBackgroundMessageHandler(backgroundMessageHandler); + } else { + // 'Android GMS or iOS' (Handle Firebase Messaging Streams + + FirebaseMessaging.instance.getInitialMessage().then((RemoteMessage message) async { + print("Firebase getInitialMessage!!!"); + // Utils.showPermissionConsentDialog(context, "getInitialMessage", (){}); + if (Platform.isIOS) + await Future.delayed(Duration(milliseconds: 3000)).then((value) { + if (message != null) newMessage(message); + }); + else + // if(message != null) newMessage(message); - }); - else - newMessage(message); - }); + }); - FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) async { - print("Firebase onMessageOpenedApp!!!"); - // Utils.showPermissionConsentDialog(context, "onMessageOpenedApp", (){}); - // newMessage(message); - if (Platform.isIOS) - await Future.delayed(Duration(milliseconds: 3000)).then((value) { + FirebaseMessaging.onMessage.listen((RemoteMessage message) async { + print("Firebase onMessage!!!"); + // Utils.showPermissionConsentDialog(context, "onMessage", (){}); + // newMessage(message); + if (Platform.isIOS) + await Future.delayed(Duration(milliseconds: 3000)).then((value) { + newMessage(message); + }); + else newMessage(message); - }); - else - newMessage(message); - }); + }); - FirebaseMessaging.instance.onTokenRefresh.listen((fcm_token) { - onToken(fcm_token); - }); + FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) async { + print("Firebase onMessageOpenedApp!!!"); + // Utils.showPermissionConsentDialog(context, "onMessageOpenedApp", (){}); + // newMessage(message); + if (Platform.isIOS) + await Future.delayed(Duration(milliseconds: 3000)).then((value) { + newMessage(message); + }); + else + newMessage(message); + }); - FirebaseMessaging.onBackgroundMessage(backgroundMessageHandler); - // } + FirebaseMessaging.instance.onTokenRefresh.listen((fcm_token) { + onToken(fcm_token); + }); + + FirebaseMessaging.onBackgroundMessage(backgroundMessageHandler); + } } newMessage(RemoteMessage remoteMessage) async { diff --git a/lib/widgets/in_app_browser/InAppBrowser.dart b/lib/widgets/in_app_browser/InAppBrowser.dart index 66d26ed6..5ccffc59 100644 --- a/lib/widgets/in_app_browser/InAppBrowser.dart +++ b/lib/widgets/in_app_browser/InAppBrowser.dart @@ -32,13 +32,13 @@ class MyInAppBrowser extends InAppBrowser { static String APPLE_PAY_PAYFORT_URL = 'https://hmgwebservices.com/PayFortWebLive/PayFortApi/MakeApplePayRequest'; // Payfort Payment Gateway URL LIVE // static String APPLE_PAY_PAYFORT_URL = 'https://hmgwebservices.com/PayFortWeb/PayFortApi/MakeApplePayRequest'; // Payfort Payment Gateway URL UAT - static String SERVICE_URL = 'https://hmgwebservices.com/PayFortWeb/pages/SendPayFortRequest.aspx'; // Payfort Payment Gateway URL UAT + // static String SERVICE_URL = 'https://hmgwebservices.com/PayFortWeb/pages/SendPayFortRequest.aspx'; // Payfort Payment Gateway URL UAT - // static String SERVICE_URL = 'https://hmgwebservices.com/PayFortWebLive/pages/SendPayFortRequest.aspx'; //Payfort Payment Gateway URL LIVE + static String SERVICE_URL = 'https://hmgwebservices.com/PayFortWebLive/pages/SendPayFortRequest.aspx'; //Payfort Payment Gateway URL LIVE - static String PREAUTH_SERVICE_URL = 'https://hmgwebservices.com/PayFortWeb/pages/SendPayFortRequest.aspx'; // Payfort PreAuth Payment Gateway URL UAT + // static String PREAUTH_SERVICE_URL = 'https://hmgwebservices.com/PayFortWeb/pages/SendPayFortRequest.aspx'; // Payfort PreAuth Payment Gateway URL UAT - // static String PREAUTH_SERVICE_URL = 'https://hmgwebservices.com/PayFortWebLive/pages/SendPayFortRequest.aspx'; //Payfort PreAuth Payment Gateway URL Live Store + static String PREAUTH_SERVICE_URL = 'https://hmgwebservices.com/PayFortWebLive/pages/SendPayFortRequest.aspx'; //Payfort PreAuth Payment Gateway URL Live Store // static String PRESCRIPTION_PAYMENT_WITH_ORDERID = // 'https://uat.hmgwebservices.com/epharmacy/checkout/OpcCompleteRedirectionPaymentClientbyOrder?orderID='; diff --git a/lib/widgets/pickupLocation/PickupLocationFromMap.dart b/lib/widgets/pickupLocation/PickupLocationFromMap.dart index 9a3ff303..f9bd92d2 100644 --- a/lib/widgets/pickupLocation/PickupLocationFromMap.dart +++ b/lib/widgets/pickupLocation/PickupLocationFromMap.dart @@ -1,18 +1,22 @@ import 'package:diplomaticquarterapp/config/config.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; +import 'package:diplomaticquarterapp/models/ambulanceRequest/locationDetails.dart'; +import 'package:diplomaticquarterapp/theme/colors.dart'; +import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; -import 'package:diplomaticquarterapp/widgets/buttons/borderedButton.dart'; +import 'package:diplomaticquarterapp/widgets/app_map/google_huawei_map.dart'; import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; -import 'package:diplomaticquarterapp/widgets/others/close_back.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_hms_gms_availability/flutter_hms_gms_availability.dart'; +import 'package:geocoding/geocoding.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:google_maps_place_picker/google_maps_place_picker.dart'; import 'package:provider/provider.dart'; -class PickupLocationFromMap extends StatelessWidget { - final Function(PickResult) onPick; +class PickupLocationFromMap extends StatefulWidget { + final Function(LocationDetails) onPick; final double latitude; final double longitude; final bool isWithAppBar; @@ -21,6 +25,54 @@ class PickupLocationFromMap extends StatelessWidget { const PickupLocationFromMap({Key key, this.onPick, this.latitude, this.longitude, this.isWithAppBar = true, this.buttonLabel, this.buttonColor}) : super(key: key); + @override + State createState() => _PickupLocationFromMapState(); +} + +class _PickupLocationFromMapState extends State { + bool isHuawei = false; + Placemark selectedPlace; + AppMap appMap; + LatLng currentPostion; + AppSharedPreferences sharedPref = AppSharedPreferences(); + double latitude = 0; + double longitude = 0; + + static CameraPosition kGooglePlex = CameraPosition( + target: LatLng(37.42796133580664, -122.085749655962), + zoom: 14.4746, + ); + + @override + void initState() { + checkIsHuawei(); + + appMap = AppMap( + kGooglePlex.toMap(), + onCameraMove: (camera) { + _updatePosition(camera); + }, + onMapCreated: () { + currentPostion = LatLng(widget.latitude, widget.longitude); + latitude = widget.latitude; + longitude = widget.longitude; + setState(() {}); + }, + onCameraIdle: () async { + List placemarks = await placemarkFromCoordinates(latitude, longitude); + selectedPlace = placemarks[0]; + print(selectedPlace); + }, + ); + super.initState(); + } + + checkIsHuawei() async { + isHuawei = await FlutterHmsGmsAvailability.isHmsAvailable; + print(isHuawei); + setState(() {}); + } + @override Widget build(BuildContext context) { ProjectViewModel projectViewModel = Provider.of(context); @@ -29,58 +81,92 @@ class PickupLocationFromMap extends StatelessWidget { showNewAppBarTitle: true, showNewAppBar: true, appBarTitle: TranslationBase.of(context).selectLocation, - // appBar: isWithAppBar - // ? AppBar( - // elevation: 0, - // textTheme: TextTheme( - // headline6: - // TextStyle(color: Colors.white, fontWeight: FontWeight.bold), - // ), - // title: Text('Location'), - // leading: CloseBack(), - // centerTitle: true, - // ) - // : null, - body: PlacePicker( - apiKey: GOOGLE_API_KEY, - enableMyLocationButton: true, - automaticallyImplyAppBarLeading: false, - autocompleteLanguage: projectViewModel.currentLanguage, - enableMapTypeButton: true, - selectInitialPosition: true, - region: "SA", - onPlacePicked: (PickResult result) { - print(result.adrAddress); - onPick(result); - Navigator.of(context).pop(); - }, - selectedPlaceWidgetBuilder: (_, selectedPlace, state, isSearchBarFocused) { - print("state: $state, isSearchBarFocused: $isSearchBarFocused"); - return isSearchBarFocused - ? Container() - : FloatingCard( - bottomPosition: 0.0, - leftPosition: 0.0, - rightPosition: 0.0, - width: 500, - borderRadius: BorderRadius.circular(12.0), - child: state == SearchingState.Searching - ? Center(child: CircularProgressIndicator()) - : Container( - margin: EdgeInsets.all(12), - child: DefaultButton( - TranslationBase.of(context).next, - () { - onPick(selectedPlace); - Navigator.of(context).pop(); - }, - ), + body: isHuawei + ? Column( + children: [ + Expanded( + child: Stack( + alignment: Alignment.center, + children: [ + if (appMap != null) appMap, + Container( + margin: EdgeInsets.only(bottom: 50.0), + child: Icon( + Icons.place, + color: CustomColors.accentColor, + size: 50, ), - ); - }, - initialPosition: LatLng(latitude, longitude), - useCurrentLocation: true, - ), + ), + ], + ), + ), + Container( + padding: const EdgeInsets.only(left: 20, right: 20, top: 14, bottom: 14), + child: DefaultButton(TranslationBase.of(context).next, () async { + LocationDetails locationDetails = new LocationDetails(); + locationDetails.lat = latitude; + locationDetails.long = longitude; + locationDetails.formattedAddress = selectedPlace.street; + widget.onPick(locationDetails); + Navigator.of(context).pop(); + }), + ), + ], + ) + : PlacePicker( + apiKey: GOOGLE_API_KEY, + enableMyLocationButton: true, + automaticallyImplyAppBarLeading: false, + autocompleteLanguage: projectViewModel.currentLanguage, + enableMapTypeButton: true, + selectInitialPosition: true, + region: "SA", + onPlacePicked: (PickResult result) { + LocationDetails locationDetails = new LocationDetails(); + locationDetails.lat = latitude; + locationDetails.long = longitude; + locationDetails.formattedAddress = result.formattedAddress; + print(result.adrAddress); + widget.onPick(locationDetails); + Navigator.of(context).pop(); + }, + selectedPlaceWidgetBuilder: (_, selectedPlace, state, isSearchBarFocused) { + print("state: $state, isSearchBarFocused: $isSearchBarFocused"); + return isSearchBarFocused + ? Container() + : FloatingCard( + bottomPosition: 0.0, + leftPosition: 0.0, + rightPosition: 0.0, + width: 500, + borderRadius: BorderRadius.circular(12.0), + child: state == SearchingState.Searching + ? Center(child: CircularProgressIndicator()) + : Container( + margin: EdgeInsets.all(12), + child: DefaultButton( + TranslationBase.of(context).next, + () { + LocationDetails locationDetails = new LocationDetails(); + locationDetails.lat = latitude; + locationDetails.long = longitude; + locationDetails.formattedAddress = selectedPlace.formattedAddress; + widget.onPick(locationDetails); + Navigator.of(context).pop(); + }, + ), + ), + ); + }, + initialPosition: LatLng(widget.latitude, widget.longitude), + useCurrentLocation: true, + ), ); } + + void _updatePosition(CameraPosition _position) { + print(_position); + latitude = _position.target.latitude; + longitude = _position.target.longitude; + } } diff --git a/pubspec.yaml b/pubspec.yaml index 38f9b42c..3de4d3db 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,8 +1,7 @@ name: diplomaticquarterapp description: A new Flutter application. - -version: 4.4.9+40409 +version: 4.4.92+404092 environment: sdk: ">=2.7.0 <3.0.0"