Add location permission request
This commit is contained in:
@@ -3,6 +3,7 @@ import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:google_maps_cluster_manager/google_maps_cluster_manager.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'package:sfm_app/feature/devices/device_model.dart';
|
||||
@@ -10,6 +11,7 @@ import 'package:sfm_app/feature/map/map_bloc.dart';
|
||||
import 'package:sfm_app/feature/map/widget/on_tap_marker_widget.dart';
|
||||
import 'package:sfm_app/product/base/bloc/base_bloc.dart';
|
||||
import 'package:sfm_app/product/constant/icon/icon_constants.dart';
|
||||
import 'package:sfm_app/product/permission/location_permission.dart';
|
||||
import 'package:sfm_app/product/services/api_services.dart';
|
||||
|
||||
class MapScreen extends StatefulWidget {
|
||||
@@ -19,7 +21,7 @@ class MapScreen extends StatefulWidget {
|
||||
State<MapScreen> createState() => _MapScreenState();
|
||||
}
|
||||
|
||||
class _MapScreenState extends State<MapScreen> {
|
||||
class _MapScreenState extends State<MapScreen> with WidgetsBindingObserver {
|
||||
late BitmapDescriptor normalIcon;
|
||||
late BitmapDescriptor offlineIcon;
|
||||
late BitmapDescriptor abnormalIcon;
|
||||
@@ -47,7 +49,8 @@ class _MapScreenState extends State<MapScreen> {
|
||||
Set<Marker> markersAll = {};
|
||||
List<Marker> markers = [];
|
||||
LatLng myLocation = const LatLng(213761, 123123);
|
||||
|
||||
Position? position;
|
||||
bool isAllowLocationPermission = false;
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -143,17 +146,27 @@ class _MapScreenState extends State<MapScreen> {
|
||||
cluster.getId(),
|
||||
),
|
||||
position: cluster.location,
|
||||
onTap: () {
|
||||
onTapMarker(
|
||||
onTap: () async {
|
||||
bool check = await checkLocationPermission(context);
|
||||
if (check == true) {
|
||||
Position position = await Geolocator.getCurrentPosition();
|
||||
// ignore: use_build_context_synchronously
|
||||
onTapMarker(
|
||||
context,
|
||||
_controller,
|
||||
mapBloc,
|
||||
myLocation,
|
||||
LatLng(position.latitude, position.longitude),
|
||||
cluster.items,
|
||||
imageAssets,
|
||||
markers,
|
||||
hospitalIcon,
|
||||
fireStationIcon);
|
||||
fireStationIcon,
|
||||
);
|
||||
} else {
|
||||
// ignore: use_build_context_synchronously
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text("Cannot get your Location")));
|
||||
}
|
||||
},
|
||||
icon: getMarkerIcon(cluster),
|
||||
);
|
||||
@@ -234,4 +247,10 @@ class _MapScreenState extends State<MapScreen> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> checkLocationPermission(context) async {
|
||||
bool check = await LocationPermissionRequest.instance
|
||||
.checkLocationPermission(context);
|
||||
return check;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user