|
|
|
|
@ -54,10 +54,16 @@
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
import 'dart:async';
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/core/app_assets.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/core/app_state.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/core/dependencies.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/core/location_util.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/core/utils/utils.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/core/utils/size_utils.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/generated/locale_keys.g.dart';
|
|
|
|
|
@ -72,7 +78,7 @@ class GMSMap extends StatefulWidget {
|
|
|
|
|
final bool myLocationEnabled;
|
|
|
|
|
final bool showCenterMarker;
|
|
|
|
|
final Completer<GoogleMapController>? inputController;
|
|
|
|
|
final num bottomPaddingHeight;
|
|
|
|
|
final double bottomPaddingHeight;
|
|
|
|
|
|
|
|
|
|
const GMSMap({
|
|
|
|
|
super.key,
|
|
|
|
|
@ -93,6 +99,7 @@ class GMSMap extends StatefulWidget {
|
|
|
|
|
|
|
|
|
|
class _GMSMapState extends State<GMSMap> {
|
|
|
|
|
late Completer<GoogleMapController> _controller;
|
|
|
|
|
GoogleMapController? _activeController;
|
|
|
|
|
late MapType _selectedMapType;
|
|
|
|
|
bool _showMapTypeSelector = false;
|
|
|
|
|
num bottomPaddingHeight = 0;
|
|
|
|
|
@ -139,6 +146,37 @@ class _GMSMapState extends State<GMSMap> {
|
|
|
|
|
setState(() => _showMapTypeSelector = !_showMapTypeSelector);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _animateToMyLocation() async {
|
|
|
|
|
final appState = getIt.get<AppState>();
|
|
|
|
|
final locationUtils = getIt.get<LocationUtils>();
|
|
|
|
|
|
|
|
|
|
void _moveToLocation() {
|
|
|
|
|
if (appState.userLat != 0.0 && appState.userLong != 0.0 && _activeController != null) {
|
|
|
|
|
_activeController!.animateCamera(
|
|
|
|
|
CameraUpdate.newCameraPosition(
|
|
|
|
|
CameraPosition(
|
|
|
|
|
target: LatLng(appState.userLat, appState.userLong),
|
|
|
|
|
zoom: 16,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (appState.userLat != 0.0 && appState.userLong != 0.0) {
|
|
|
|
|
_moveToLocation();
|
|
|
|
|
} else {
|
|
|
|
|
locationUtils.getLocation(
|
|
|
|
|
isShowConfirmDialog: true,
|
|
|
|
|
onSuccess: (latLng) {
|
|
|
|
|
_moveToLocation();
|
|
|
|
|
},
|
|
|
|
|
onFailure: () {},
|
|
|
|
|
onLocationDeniedForever: () {},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Stack(
|
|
|
|
|
@ -146,16 +184,21 @@ class _GMSMapState extends State<GMSMap> {
|
|
|
|
|
// ── Google Map ──────────────────────────────────────────────────
|
|
|
|
|
GoogleMap(
|
|
|
|
|
mapType: _selectedMapType,
|
|
|
|
|
zoomControlsEnabled: true,
|
|
|
|
|
myLocationEnabled: widget.myLocationEnabled,
|
|
|
|
|
myLocationButtonEnabled: true,
|
|
|
|
|
padding: EdgeInsets.only(bottom: double.parse(widget.bottomPaddingHeight.toString())),
|
|
|
|
|
zoomControlsEnabled: false,
|
|
|
|
|
// myLocationEnabled: widget.myLocationEnabled,
|
|
|
|
|
myLocationEnabled: true,
|
|
|
|
|
myLocationButtonEnabled: false,
|
|
|
|
|
// padding: EdgeInsets.only(bottom: double.parse(widget.bottomPaddingHeight.toString())),
|
|
|
|
|
// padding: EdgeInsets.only(top: Platform.isAndroid ? double.parse(widget.bottomPaddingHeight.toString()) : 0, bottom: Platform.isIOS ? double.parse(widget.bottomPaddingHeight.toString()) : 0),
|
|
|
|
|
compassEnabled: widget.compassEnabled,
|
|
|
|
|
initialCameraPosition: widget.currentLocation,
|
|
|
|
|
onCameraMove: widget.onCameraMoved,
|
|
|
|
|
onCameraIdle: widget.onCameraIdle,
|
|
|
|
|
onMapCreated: (GoogleMapController controller) {
|
|
|
|
|
_controller.complete(controller);
|
|
|
|
|
_activeController = controller;
|
|
|
|
|
if (!_controller.isCompleted) {
|
|
|
|
|
_controller.complete(controller);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
@ -167,9 +210,33 @@ class _GMSMapState extends State<GMSMap> {
|
|
|
|
|
Icons.location_pin,
|
|
|
|
|
size: 36.h,
|
|
|
|
|
color: AppColors.primaryRedColor,
|
|
|
|
|
).paddingOnly(bottom: double.parse((widget.bottomPaddingHeight + 25.h).toString())),
|
|
|
|
|
).paddingOnly(bottom: Platform.isAndroid ? 30.h : double.parse((widget.bottomPaddingHeight + 25.h).toString())),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
// ── My Location button ────────────────────────────────────────────
|
|
|
|
|
PositionedDirectional(
|
|
|
|
|
// bottom: 300.h,
|
|
|
|
|
// bottom: 400.h,
|
|
|
|
|
bottom: widget.bottomPaddingHeight,
|
|
|
|
|
start: 16.w,
|
|
|
|
|
child: GestureDetector(
|
|
|
|
|
onTap: _animateToMyLocation,
|
|
|
|
|
child: Container(
|
|
|
|
|
width: 42.w,
|
|
|
|
|
height: 42.h,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: AppColors.whiteColor,
|
|
|
|
|
borderRadius: BorderRadius.circular(8.r),
|
|
|
|
|
),
|
|
|
|
|
child: Icon(
|
|
|
|
|
Icons.my_location,
|
|
|
|
|
size: 22.h,
|
|
|
|
|
color: AppColors.blackBgColor,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
// ── Map-type toggle button ──────────────────────────────────────
|
|
|
|
|
PositionedDirectional(
|
|
|
|
|
top: 48.h,
|
|
|
|
|
|