Skip to content

fixed: Location Permission related issues #829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ class AddOrUpdateAlarmController extends GetxController {
// Cannot request runtime permission because location permission
// is denied forever.
return false;
} else if (locationPermission == LocationPermission.denied) {
} else if (locationPermission == LocationPermission.denied ||
locationPermission == LocationPermission.whileInUse) {
bool? shouldAskPermission = await Get.defaultDialog<bool>(
backgroundColor: themeController.secondaryBackgroundColor.value,
barrierDismissible: false,
Expand All @@ -365,7 +366,7 @@ class AddOrUpdateAlarmController extends GetxController {
color: themeController.primaryTextColor.value,
),
content: const Text(
'To ensure timely alarm dismissal, this app requires access to your location. Your location will be accessed in the background at the scheduled alarm time.',
'To ensure timely alarm dismissal, this app requires access to your location. Please select Allow all the time. Your location will only be accessed in the background at the scheduled alarm time.',
),
actions: [
TextButton(
Expand Down Expand Up @@ -398,17 +399,13 @@ class AddOrUpdateAlarmController extends GetxController {
// User declined the permission request.
return false;
}
// Ask the user for location permission.
// Ask the user for location permission (must be LocationPermission.always).
locationPermission = await FlLocation.requestLocationPermission();
if (locationPermission == LocationPermission.denied ||
locationPermission == LocationPermission.deniedForever) return false;
locationPermission == LocationPermission.deniedForever ||
locationPermission == LocationPermission.whileInUse) return false;
}

// Location permission must always be allowed (LocationPermission.always)
// to collect location data in the background.
if (background == true &&
locationPermission == LocationPermission.whileInUse) return false;

// Location services has been enabled and permission have been granted.
return true;
}
Expand Down
113 changes: 62 additions & 51 deletions lib/app/modules/addOrUpdateAlarm/views/location_activity_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,60 +98,71 @@ class LocationTile extends StatelessWidget {
if (value == 0) {
controller.isLocationEnabled.value = false;
} else if (value == 1) {
Get.defaultDialog(
backgroundColor: themeController.secondaryBackgroundColor.value,
title: 'Set location to automatically cancel alarm!',
titleStyle: Theme.of(context).textTheme.bodyMedium,
content: Column(
children: [
SizedBox(
height: height * 0.65,
width: width * 0.92,
child: FlutterMap(
mapController: controller.mapController,
options: MapOptions(
onTap: (tapPosition, point) {
controller.selectedPoint.value = point;
},
// screenSize: Size(width * 0.3, height * 0.8),
center: controller.selectedPoint.value,
zoom: 15,
),
children: [
TileLayer(
urlTemplate:
'https://{s}tile.openstreetmap.org/{z}/{x}/{y}.png',
if(await controller.checkAndRequestPermission()){
Get.defaultDialog(
backgroundColor: themeController.secondaryBackgroundColor.value,
title: 'Set location to automatically cancel alarm!',
titleStyle: Theme.of(context).textTheme.bodyMedium,
content: Column(
children: [
SizedBox(
height: height * 0.65,
width: width * 0.92,
child: FlutterMap(
mapController: controller.mapController,
options: MapOptions(
onTap: (tapPosition, point) {
controller.selectedPoint.value = point;
},
// screenSize: Size(width * 0.3, height * 0.8),
center: controller.selectedPoint.value,
zoom: 15,
),
Obx(() => MarkerLayer(
markers:
List<Marker>.from(controller.markersList))),
],
),
),
const SizedBox(height: 10),
TextButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(kprimaryColor),
),
child: Text(
'Save',
style: Theme.of(context).textTheme.displaySmall!.copyWith(
color: themeController.secondaryTextColor.value,
children: [
TileLayer(
urlTemplate:
'https://{s}tile.openstreetmap.org/{z}/{x}/{y}.png',
),
Obx(() => MarkerLayer(
markers:
List<Marker>.from(controller.markersList))),
],
),
),
onPressed: () {
Utils.hapticFeedback();
Get.back();
controller.isLocationEnabled.value = true;
},
),
],
),
);

if (controller.isLocationEnabled.value == false) {
await controller.getLocation();
controller.mapController.move(controller.selectedPoint.value, 15);
const SizedBox(height: 10),
TextButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(kprimaryColor),
),
child: Text(
'Save',
style: Theme.of(context).textTheme.displaySmall!.copyWith(
color: themeController.secondaryTextColor.value,
),
),
onPressed: () {
Utils.hapticFeedback();
Get.back();
controller.isLocationEnabled.value = true;
},
),
],
),
);

if (controller.isLocationEnabled.value == false) {
await controller.getLocation();
controller.mapController.move(controller.selectedPoint.value, 15);
}
}
else {
Get.defaultDialog(
titlePadding: const EdgeInsets.symmetric(vertical: 20),
backgroundColor: themeController.secondaryBackgroundColor.value,
title: 'Location Permission Denied!'.tr,
titleStyle: Theme.of(context).textTheme.displaySmall,
content: const Text('Please provide all time location access to use this feature.', textAlign: TextAlign.center,),
);
}
}
});
Expand Down
96 changes: 53 additions & 43 deletions lib/app/modules/addOrUpdateAlarm/views/weather_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,50 +24,60 @@ class WeatherTile extends StatelessWidget {
child: ListTile(
onTap: () async {
Utils.hapticFeedback();
await controller.checkAndRequestPermission();
Get.defaultDialog(
titlePadding: const EdgeInsets.symmetric(vertical: 20),
backgroundColor: themeController.secondaryBackgroundColor.value,
title: 'Select weather types'.tr,
titleStyle: Theme.of(context).textTheme.displaySmall,
content: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
WeatherOption(
type: WeatherTypes.sunny,
label: 'Sunny',
controller: controller,
themeController: themeController,
),
WeatherOption(
type: WeatherTypes.cloudy,
label: 'Cloudy',
controller: controller,
themeController: themeController,
),
WeatherOption(
type: WeatherTypes.rainy,
label: 'Rainy',
controller: controller,
themeController: themeController,
),
WeatherOption(
type: WeatherTypes.windy,
label: 'Windy',
controller: controller,
themeController: themeController,
),
WeatherOption(
type: WeatherTypes.stormy,
label: 'Stormy',
controller: controller,
themeController: themeController,
),
],
if(await controller.checkAndRequestPermission()){
Get.defaultDialog(
titlePadding: const EdgeInsets.symmetric(vertical: 20),
backgroundColor: themeController.secondaryBackgroundColor.value,
title: 'Select weather types'.tr,
titleStyle: Theme.of(context).textTheme.displaySmall,
content: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
WeatherOption(
type: WeatherTypes.sunny,
label: 'Sunny',
controller: controller,
themeController: themeController,
),
WeatherOption(
type: WeatherTypes.cloudy,
label: 'Cloudy',
controller: controller,
themeController: themeController,
),
WeatherOption(
type: WeatherTypes.rainy,
label: 'Rainy',
controller: controller,
themeController: themeController,
),
WeatherOption(
type: WeatherTypes.windy,
label: 'Windy',
controller: controller,
themeController: themeController,
),
WeatherOption(
type: WeatherTypes.stormy,
label: 'Stormy',
controller: controller,
themeController: themeController,
),
],
),
),
),
);
);
}
else {
Get.defaultDialog(
titlePadding: const EdgeInsets.symmetric(vertical: 20),
backgroundColor: themeController.secondaryBackgroundColor.value,
title: 'Location Permission Denied!'.tr,
titleStyle: Theme.of(context).textTheme.displaySmall,
content: const Text('Please provide all time location access to use this feature.', textAlign: TextAlign.center,),
);
}
},
title: Row(
children: [
Expand Down