juliansteenbakker / flutter_ble_peripheral

A Flutter package for advertising BLE data in peripheral mode
BSD 3-Clause "New" or "Revised" License
72 stars 50 forks source link

Unhandled Exception: MissingPluginException(requestPermissions) #151

Open RubenGarcia opened 1 year ago

RubenGarcia commented 1 year ago
FlutterBlePeripheral flutterBlePeripheral = FlutterBlePeripheral();
BluetoothPeripheralState peripheralPermission = await flutterBlePeripheral.requestPermission();

throws this, although the permission is granted. Please investigate.

E/flutter ( 2983): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method requestPermissions on channel dev.steenbakker.flutter_ble_peripheral/ble_state)
E/flutter ( 2983): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:308:7)
E/flutter ( 2983): <asynchronous suspension>
E/flutter ( 2983): #1      FlutterBlePeripheral.requestPermission (package:flutter_ble_peripheral/src/flutter_ble_peripheral.dart:135:9)
E/flutter ( 2983): <asynchronous suspension>

Android 12 (Pixel 3).

  flutter_ble_peripheral:
    dependency: "direct main"
    description:
      name: flutter_ble_peripheral
      sha256: aab19e5268f90237ab02cd084844596c37f76285f93759709742bab5627a76ac
      url: "https://pub.dev"
    source: hosted
    version: "1.2.1"

I followed the instructions on https://pub.dev/packages/flutter_ble_peripheral/install but cloning your repository, the example app works. Please add any additional configuration to https://pub.dev/packages/flutter_ble_peripheral/install

RubenGarcia commented 1 year ago

Following https://stackoverflow.com/questions/71646547/unhandled-exception-missingpluginexceptionno-implementation-found-for-method-f did not solve the issue. Clicking on stop and play also did not solve the issue.

RubenGarcia commented 1 year ago

Another comment. https://pub.dev/packages/flutter_ble_peripheral/example uses always await FlutterBlePeripheral().XXX and does not save the result of FlutterBlePeripheral() into a variable for later use. Is saving it into a variable forbidden?

RubenGarcia commented 1 year ago

Changing the code to use FlutterBlePeripheral() everywhere did not change behaviour.

RubenGarcia commented 1 year ago

Workaround: use import 'package:permission_handler/permission_handler.dart'; to request the permissions explicitly.