Skip to content
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

update to add location perms for BLE #93

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
92 changes: 71 additions & 21 deletions apps/AppWithWearable/lib/onboarding/welcome/welcome_widget.dart
Expand Up @@ -151,46 +151,54 @@ class _WelcomeWidgetState extends State<WelcomeWidget> with SingleTickerProvider
mouseCursor: SystemMouseCursors.click,
onTap: () async {
// Check if Bluetooth permission is granted
PermissionStatus bluetoothStatus =
await Permission.bluetooth.status;
PermissionStatus bluetoothStatus = await Permission.bluetooth.status;

if (!bluetoothStatus.isGranted) {
// Request Bluetooth permission if not already granted
bluetoothStatus = await Permission.bluetooth.request();
}

if (bluetoothStatus.isGranted) {
// Bluetooth permission is already granted
// Request notification permission
PermissionStatus notificationStatus =
await Permission.notification.request();
// Bluetooth permission is granted

// Now check and request ACCESS_FINE_LOCATION permission
PermissionStatus locationStatus = await Permission.location.status;
if (!locationStatus.isGranted) {
// Request ACCESS_FINE_LOCATION permission if not already granted
locationStatus = await Permission.location.request();
}

if (locationStatus.isGranted) {

// Navigate to the 'scanDevices' screen
context.goNamed('findDevices');
} else {
// Bluetooth permission is not granted
if (await Permission.bluetooth
.request()
.isGranted) {
// Bluetooth permission is granted now
// Request notification permission
PermissionStatus notificationStatus =
await Permission.notification.request();
PermissionStatus notificationStatus = await Permission.notification.request();
if (notificationStatus.isGranted) {
// Notification permission is granted

// Navigate to the 'scanDevices' screen
context.goNamed('findDevices');
// Navigate to the 'scanDevices' screen
context.goNamed('findDevices');
} else {
// Handle the case when notification permission is denied
// You can show a dialog or a notification to the user
}
} else {
// Bluetooth permission is denied
// ACCESS_FINE_LOCATION permission is denied
// Show a dialog to inform the user and provide an action to open app settings
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
backgroundColor: Colors.grey[900],
title: Text(
'Bluetooth Required',
'Location Required',
style: TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
content: Text(
'This app needs Bluetooth to function properly. Please enable it in the settings.',
'This app needs location access to function properly. Please enable it in the settings.',
style: TextStyle(
color: Colors.white,
fontSize: 16,
Expand All @@ -216,6 +224,48 @@ class _WelcomeWidgetState extends State<WelcomeWidget> with SingleTickerProvider
},
);
}
} else {
// Bluetooth permission is denied
// Show a dialog to inform the user and provide an action to open app settings
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
backgroundColor: Colors.grey[900],
title: Text(
'Bluetooth Required',
style: TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
content: Text(
'This app needs Bluetooth to function properly. Please enable it in the settings.',
style: TextStyle(
color: Colors.white,
fontSize: 16,
),
),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
openAppSettings();
},
child: Text(
'OK',
style: TextStyle(
color: Colors.blue,
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
],
);
},
);
}
},
child: ShaderMask(
Expand Down