Skip to content

Commit

Permalink
alert now shows and makes app unusable when bluetooth is turned off o…
Browse files Browse the repository at this point in the history
…r permissions are not given
  • Loading branch information
o-bagge committed Dec 18, 2023
1 parent 84b7077 commit 3b7423d
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 18 deletions.
6 changes: 6 additions & 0 deletions open_earable/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
PODS:
- app_settings (5.1.1):
- Flutter
- Flutter (1.0.0)
- flutter_gl (0.0.3):
- Flutter
Expand All @@ -21,6 +23,7 @@ PODS:
- three3d_egl (0.1.3)

DEPENDENCIES:
- app_settings (from `.symlinks/plugins/app_settings/ios`)
- Flutter (from `Flutter`)
- flutter_gl (from `.symlinks/plugins/flutter_gl/ios`)
- flutter_native_splash (from `.symlinks/plugins/flutter_native_splash/ios`)
Expand All @@ -36,6 +39,8 @@ SPEC REPOS:
- three3d_egl

EXTERNAL SOURCES:
app_settings:
:path: ".symlinks/plugins/app_settings/ios"
Flutter:
:path: Flutter
flutter_gl:
Expand All @@ -52,6 +57,7 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/reactive_ble_mobile/ios"

SPEC CHECKSUMS:
app_settings: 017320c6a680cdc94c799949d95b84cb69389ebc
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
flutter_gl: 5a5603f35db897697f064027864a32b15d0c421d
flutter_native_splash: 52501b97d1c0a5f898d687f1646226c1f93c56ef
Expand Down
62 changes: 60 additions & 2 deletions open_earable/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:provider/provider.dart';
import 'package:flutter/material.dart';
import 'package:open_earable/open_earable_icon_icons.dart';
Expand All @@ -8,6 +10,8 @@ import 'apps_tab.dart';
import 'package:open_earable_flutter/src/open_earable_flutter.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:open_earable/controls_tab/models/open_earable_settings.dart';
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
import 'package:app_settings/app_settings.dart';

void main() => runApp(MyApp());

Expand Down Expand Up @@ -46,12 +50,14 @@ class MyHomePage extends StatefulWidget {
class _MyHomePageState extends State<MyHomePage> {
int _selectedIndex = 0;
late OpenEarable _openEarable;

final flutterReactiveBle = FlutterReactiveBle();
late bool alertOpen;
late List<Widget> _widgetOptions;

StreamSubscription? blePermissionSubscription;
@override
void initState() {
super.initState();
alertOpen = false;
_checkBLEPermission();
_openEarable = OpenEarable();
_widgetOptions = <Widget>[
Expand All @@ -61,13 +67,65 @@ class _MyHomePageState extends State<MyHomePage> {
];
}

@override
dispose() {
super.dispose();
blePermissionSubscription?.cancel();
}

Future<void> _checkBLEPermission() async {
PermissionStatus status = await Permission.bluetoothConnect.request();
PermissionStatus status2 = await Permission.location.request();
PermissionStatus status3 = await Permission.bluetoothScan.request();
if (status.isGranted) {
print("BLE is working");
}
blePermissionSubscription =
flutterReactiveBle.statusStream.listen((status) {
if (status != BleStatus.ready &&
status != BleStatus.unknown &&
alertOpen == false) {
alertOpen = true;
_showBluetoothAlert(context);
}
});
}

void _showBluetoothAlert(BuildContext context) {
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
title: Text("Bluetooth disabled"),
content: Text(
"Please make sure your device's bluetooth and location services are turned on and this app has been granted permission to use them in the app's settings.\nThis alert can only be closed if these requirements are fulfilled."),
actions: <Widget>[
TextButton(
child: Text(
'Open App Settings',
style: TextStyle(
color: Theme.of(context).colorScheme.onBackground),
),
onPressed: () {
AppSettings.openAppSettings();
},
),
TextButton(
child: Text('OK',
style: TextStyle(
color: Theme.of(context).colorScheme.onBackground)),
onPressed: () {
if (flutterReactiveBle.status == BleStatus.ready) {
alertOpen = false;
Navigator.of(context).pop();
}
},
),
],
);
},
);
}

void _onItemTapped(int index) {
Expand Down
46 changes: 31 additions & 15 deletions open_earable/pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
app_settings:
dependency: "direct main"
description:
name: app_settings
sha256: "09bc7fe0313a507087bec1a3baf555f0576e816a760cbb31813a88890a09d9e5"
url: "https://pub.dev"
source: hosted
version: "5.1.1"
archive:
dependency: transitive
description:
Expand Down Expand Up @@ -232,7 +240,7 @@ packages:
source: hosted
version: "2.2.16"
flutter_reactive_ble:
dependency: transitive
dependency: "direct main"
description:
name: flutter_reactive_ble
sha256: "7a0d245412dc8e1b72ce2adc423808583b42ce824b1be74001ff22c8bb5ada48"
Expand Down Expand Up @@ -350,10 +358,10 @@ packages:
description:
path: "."
ref: HEAD
resolved-ref: eaf50163a03f24822f087a822c767c284f5b3637
resolved-ref: "6841c0b704dffbe559961ea80dccf73abf0c293a"
url: "https://github.com/OpenEarable/open_earable_flutter.git"
source: git
version: "0.0.1"
version: "0.0.2"
open_file:
dependency: "direct main"
description:
Expand Down Expand Up @@ -427,45 +435,53 @@ packages:
source: hosted
version: "2.2.1"
permission_handler:
dependency: transitive
dependency: "direct main"
description:
name: permission_handler
sha256: bc56bfe9d3f44c3c612d8d393bd9b174eb796d706759f9b495ac254e4294baa5
sha256: "860c6b871c94c78e202dc69546d4d8fd84bd59faeb36f8fb9888668a53ff4f78"
url: "https://pub.dev"
source: hosted
version: "10.4.5"
version: "11.1.0"
permission_handler_android:
dependency: transitive
description:
name: permission_handler_android
sha256: "59c6322171c29df93a22d150ad95f3aa19ed86542eaec409ab2691b8f35f9a47"
sha256: "2f1bec180ee2f5665c22faada971a8f024761f632e93ddc23310487df52dcfa6"
url: "https://pub.dev"
source: hosted
version: "10.3.6"
version: "12.0.1"
permission_handler_apple:
dependency: transitive
description:
name: permission_handler_apple
sha256: "99e220bce3f8877c78e4ace901082fb29fa1b4ebde529ad0932d8d664b34f3f5"
sha256: "1a816084338ada8d574b1cb48390e6e8b19305d5120fe3a37c98825bacc78306"
url: "https://pub.dev"
source: hosted
version: "9.2.0"
permission_handler_html:
dependency: transitive
description:
name: permission_handler_html
sha256: "11b762a8c123dced6461933a88ea1edbbe036078c3f9f41b08886e678e7864df"
url: "https://pub.dev"
source: hosted
version: "9.1.4"
version: "0.1.0+2"
permission_handler_platform_interface:
dependency: transitive
description:
name: permission_handler_platform_interface
sha256: "6760eb5ef34589224771010805bea6054ad28453906936f843a8cc4d3a55c4a4"
sha256: d87349312f7eaf6ce0adaf668daf700ac5b06af84338bd8b8574dfbd93ffe1a1
url: "https://pub.dev"
source: hosted
version: "3.12.0"
version: "4.0.2"
permission_handler_windows:
dependency: transitive
description:
name: permission_handler_windows
sha256: cc074aace208760f1eee6aa4fae766b45d947df85bc831cde77009cdb4720098
sha256: "1e8640c1e39121128da6b816d236e714d2cf17fac5a105dd6acdd3403a628004"
url: "https://pub.dev"
source: hosted
version: "0.1.3"
version: "0.2.0"
petitparser:
dependency: transitive
description:
Expand Down Expand Up @@ -691,4 +707,4 @@ packages:
version: "3.1.2"
sdks:
dart: ">=3.2.0-194.0.dev <4.0.0"
flutter: ">=3.7.0"
flutter: ">=3.16.0"
4 changes: 3 additions & 1 deletion open_earable/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ dependencies:
open_earable_flutter:
git:
url: https://github.com/OpenEarable/open_earable_flutter.git

permission_handler: ^11.1.0
flutter_reactive_ble: ^5.2.0
app_settings: ^5.1.1

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
Expand Down

0 comments on commit 3b7423d

Please sign in to comment.