diff --git a/.gitignore b/.gitignore index 96fd13e0..a8aec041 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ res/values/strings_en.arb lib/generated/ example/lib/generated/ example/.flutter-plugins-dependencies -.dart_tool/ \ No newline at end of file +.dart_tool/ +example/ios/Podfile.lock \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 3ad2bb2b..25478c46 100644 --- a/.travis.yml +++ b/.travis.yml @@ -47,7 +47,7 @@ _android_job_template: &android_job_template _ios_job_template: &ios_job_template language: objective-c os: osx - osx_image: xcode11 + osx_image: xcode11.6 xcode_workspave: example/ios/Runner.xcworkspace xcode_scheme: Runner before_script: diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ef6d943..36a34e29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.2.6 + +* Fixed scan quick failures not being reported to the listener (race condition in scanning_mixin.dart) + ## 2.2.5 * add missing handling of destroyClient call on iOS diff --git a/android/build.gradle b/android/build.gradle index 2423646c..a397b0eb 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,5 +1,5 @@ group 'com.polidea.flutter_ble_lib' -version '2.2.5' +version '2.2.6' buildscript { repositories { diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock deleted file mode 100644 index a6a5adb4..00000000 --- a/example/ios/Podfile.lock +++ /dev/null @@ -1,35 +0,0 @@ -PODS: - - Flutter (1.0.0) - - flutter_ble_lib (2.2.3): - - Flutter - - MultiplatformBleAdapter (= 0.1.5) - - MultiplatformBleAdapter (0.1.5) - - "permission_handler (4.2.0+hotfix.3)": - - Flutter - -DEPENDENCIES: - - Flutter (from `Flutter`) - - flutter_ble_lib (from `.symlinks/plugins/flutter_ble_lib/ios`) - - permission_handler (from `.symlinks/plugins/permission_handler/ios`) - -SPEC REPOS: - trunk: - - MultiplatformBleAdapter - -EXTERNAL SOURCES: - Flutter: - :path: Flutter - flutter_ble_lib: - :path: ".symlinks/plugins/flutter_ble_lib/ios" - permission_handler: - :path: ".symlinks/plugins/permission_handler/ios" - -SPEC CHECKSUMS: - Flutter: 0e3d915762c693b495b44d77113d4970485de6ec - flutter_ble_lib: 20e79f0b1d78d921d9ed68ab4451e190029bc3d9 - MultiplatformBleAdapter: 3c4391d428382738a47662ae1f665a29ce78ff39 - permission_handler: 40520ab8ad1bb78a282b832464e995ec87f77ec6 - -PODFILE CHECKSUM: 1b66dae606f75376c5f2135a8290850eeb09ae83 - -COCOAPODS: 1.8.4 diff --git a/example/lib/devices_list/devices_list_view.dart b/example/lib/devices_list/devices_list_view.dart index ff4177a0..e5ebadc1 100644 --- a/example/lib/devices_list/devices_list_view.dart +++ b/example/lib/devices_list/devices_list_view.dart @@ -19,6 +19,7 @@ class DevicesListScreen extends StatefulWidget { class DeviceListScreenState extends State { DevicesBloc _devicesBloc; StreamSubscription _appStateSubscription; + bool _shouldRunOnResume = true; @override void didUpdateWidget(DevicesListScreen oldWidget) { @@ -39,13 +40,13 @@ class DeviceListScreenState extends State { Fimber.d("navigate to details"); _onPause(); await Navigator.pushNamed(context, "/details"); - _shouldRunOnResume = true; + setState(() { + _shouldRunOnResume = true; + }); Fimber.d("back from details"); }); } - bool _shouldRunOnResume = true; - @override void didChangeDependencies() { super.didChangeDependencies(); diff --git a/ios/flutter_ble_lib.podspec b/ios/flutter_ble_lib.podspec index aa03a4bf..51f47c01 100644 --- a/ios/flutter_ble_lib.podspec +++ b/ios/flutter_ble_lib.podspec @@ -3,7 +3,7 @@ # Pod::Spec.new do |s| s.name = 'flutter_ble_lib' - s.version = '2.2.5' + s.version = '2.2.6' s.summary = 'A new flutter plugin project.' s.description = <<-DESC A new flutter plugin project. diff --git a/lib/src/bridge/scanning_mixin.dart b/lib/src/bridge/scanning_mixin.dart index 9b099f1c..d05a9809 100644 --- a/lib/src/bridge/scanning_mixin.dart +++ b/lib/src/bridge/scanning_mixin.dart @@ -1,11 +1,19 @@ part of _internal; mixin ScanningMixin on FlutterBLE { - Stream _scanEvents; + Stream _scanEvents; void _prepareScanEventsStream() { - _scanEvents = - const EventChannel(ChannelName.scanningEvents).receiveBroadcastStream(); + _scanEvents = const EventChannel(ChannelName.scanningEvents) + .receiveBroadcastStream() + .handleError( + (errorJson) => throw BleError.fromJson(jsonDecode(errorJson.details)), + test: (error) => error is PlatformException, + ) + .map( + (scanResultJson) => + ScanResult.fromJson(jsonDecode(scanResultJson), _manager), + ); } Stream startDeviceScan( @@ -13,30 +21,29 @@ mixin ScanningMixin on FlutterBLE { int callbackType, List uuids, bool allowDuplicates, - ) async* { - _methodChannel.invokeMethod( - MethodName.startDeviceScan, - { - ArgumentName.scanMode: scanMode, - ArgumentName.callbackType: callbackType, - ArgumentName.uuids: uuids, - ArgumentName.allowDuplicates: allowDuplicates, - }, - ); - + ) { if (_scanEvents == null) { _prepareScanEventsStream(); } - yield* _scanEvents.handleError( - (errorJson) { - throw BleError.fromJson(jsonDecode(errorJson.details)); - }, - test: (error) => error is PlatformException, - ).map((scanResultJson) => ScanResult.fromJson( - jsonDecode(scanResultJson), - _manager, - )); + StreamController streamController = StreamController.broadcast( + onListen: () => _methodChannel.invokeMethod( + MethodName.startDeviceScan, + { + ArgumentName.scanMode: scanMode, + ArgumentName.callbackType: callbackType, + ArgumentName.uuids: uuids, + ArgumentName.allowDuplicates: allowDuplicates, + }, + ), + onCancel: () => stopDeviceScan(), + ); + + streamController + .addStream(_scanEvents, cancelOnError: true) + .then((_) => streamController?.close()); + + return streamController.stream; } Future stopDeviceScan() async { diff --git a/pubspec.yaml b/pubspec.yaml index 9c1d1ebc..beb0c30c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_ble_lib description: FlutterBle Library is a flutter library that supports BLE operations. It uses MultiPlatformBleAdapter as a native backend.. -version: 2.2.5 +version: 2.2.6 homepage: https://github.com/Polidea/FlutterBleLib environment: