Skip to content

Commit

Permalink
Nullsafety (#586)
Browse files Browse the repository at this point in the history
* Work in progress

* lib/** nullability compliant;
added linter exceptions for string single quotes and pedantic local variable type rule

* Example:: updated to nullsafe-ready dependencies

* Example:: nullsafety + refactor WIP

* Example:: nullsafe ready

* Example/test:: nullsafe ready

* test:: using new mocking mechanism
additional fixes

* Java: added some null checks to make the calls to stop and destroy reentrant

* Example:: additional cleanup and refactor
Lib:: enchanced error handling, refined nullability on certain types

* TestFix:: the injected manager instance is not part of the Characteristic POD so should be ignored when checking for equallity

* ble_error seem to have rather nullable fields

* TestFix: little refactor on characteristic_mixin regarding clearity and type annotations

* TestFix:: lib_core_test::  tests now passing

* Example:: removed comment-disabled code

* Test:: all tests Passing now! 🎉

* Enhanced BleError nullability, so that reason always has a default value;
made fields final

* Travis fix

* disabled analysis for tests

* Travis:: still fixing ios build

* vscode:: stopped tracking settings file

* travis:: removed my additions to ios example script

* Characteristic:: Service field is now final

* gitignored andoid related staff
xcode noise

* Add bluetooth-central key to README.md (#562)

* Add bluetooth-central key to README.md

Based on #530

* Update README.md

* Travis: updated xcode version to 12.2

* BleError:: default reason text added

* ScanResult::
added final qualifiers
isConnectable is back to nullable since it's only available on iOS on android it will be null which does not mean false!!

* CharacteristicsMixin::
_parseCharacteristicWithValueWithTransactionIdResponse()::
signature is now type safe
moved the rawJsonValue String checking to the caller side

* Test:: removed dummy print

* ScanningMixin:: _prepareScanEventsStream() renamed to just _scanEvents
also _resetScanEvents introduced to null the underlying scream out

* ScanningMixin:: small refinement on naming stuff

* Characteristic:: refactor on Futures to always complete with something even if withResponse is false
additional type safety on invokeMethod calls

* Revert "Characteristic:: refactor on Futures to always complete with something even if withResponse is false"

This reverts commit 86dafd6.

Co-authored-by: Yauheni Pakala <[email protected]>
  • Loading branch information
okocsis and wcoder authored Apr 13, 2021
1 parent aaa2009 commit 1beac74
Show file tree
Hide file tree
Showing 52 changed files with 2,572 additions and 588 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ lib/generated/
example/lib/generated/
example/.flutter-plugins-dependencies
.dart_tool/
example/ios/Podfile.lock
example/ios/Podfile.lock
.vscode/settings.json
org.eclipse.buildship.core.prefs
.project
.classpath
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ _android_job_template: &android_job_template
_ios_job_template: &ios_job_template
language: objective-c
os: osx
osx_image: xcode11.6
osx_image: xcode12.2
xcode_workspave: example/ios/Runner.xcworkspace
xcode_scheme: Runner
before_script:
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ Add [Privacy - Bluetooth Always Usage Description](https://developer.apple.com/d
...
```

#### Background mode

To support background capabilities add [The `bluetooth-central` Background Execution Mode](https://developer.apple.com/library/archive/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html#//apple_ref/doc/uid/TP40013257-CH7-SW6) key to `[project]/ios/Runner/Info.plist` file.

```xml
...
<key>UIBackgroundModes</key>
<array>
<string>bluetooth-central</string>
</array>
...
```

## Usage

The library is organised around a few base entities, which are:
Expand Down
11 changes: 10 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
include: package:pedantic/analysis_options.yaml
include: package:pedantic/analysis_options.yaml

analyzer:
exclude: [test/**]

linter:
rules:
prefer_single_quotes: false
omit_local_variable_types: false
unawaited_futures: false
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ public void onEvent(Integer restoreStateIdentifier) {
}

private void destroyClient(Result result) {
bleAdapter.destroyClient();
if (bleAdapter != null) {
bleAdapter.destroyClient();
}
scanningStreamHandler.onComplete();
connectionStateStreamHandler.onComplete();
bleAdapter = null;
Expand Down Expand Up @@ -177,13 +179,17 @@ public void onError(BleError error) {
}

private void stopDeviceScan(Result result) {
bleAdapter.stopDeviceScan();
if (bleAdapter != null) {
bleAdapter.stopDeviceScan();
}
scanningStreamHandler.onComplete();
result.success(null);
}

private void cancelTransaction(MethodCall call, Result result) {
bleAdapter.cancelTransaction(call.<String>argument(ArgumentKey.TRANSACTION_ID));
if (bleAdapter != null) {
bleAdapter.cancelTransaction(call.<String>argument(ArgumentKey.TRANSACTION_ID));
}
result.success(null);
}
}
24 changes: 15 additions & 9 deletions example/lib/device_details/device_detail_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class DeviceDetailsView extends StatefulWidget {
}

class DeviceDetailsViewState extends State<DeviceDetailsView> {
DeviceDetailsBloc _deviceDetailsBloc;
StreamSubscription _appStateSubscription;
DeviceDetailsBloc? _deviceDetailsBloc;
StreamSubscription? _appStateSubscription;

bool _shouldRunOnResume = true;

Expand All @@ -33,9 +33,9 @@ class DeviceDetailsViewState extends State<DeviceDetailsView> {

void _onResume() {
Fimber.d("onResume");
_deviceDetailsBloc.init();
_deviceDetailsBloc?.init();
_appStateSubscription =
_deviceDetailsBloc.disconnectedDevice.listen((bleDevice) async {
_deviceDetailsBloc?.disconnectedDevice.listen((bleDevice) async {
Fimber.d("navigate to details");
_onPause();
Navigator.pop(context);
Expand All @@ -46,8 +46,8 @@ class DeviceDetailsViewState extends State<DeviceDetailsView> {

void _onPause() {
Fimber.d("onPause");
_appStateSubscription.cancel();
_deviceDetailsBloc.dispose();
_appStateSubscription?.cancel();
_deviceDetailsBloc?.dispose();
}

@override
Expand All @@ -59,9 +59,13 @@ class DeviceDetailsViewState extends State<DeviceDetailsView> {

@override
Widget build(BuildContext context) {
final deviceDetailsBloc = _deviceDetailsBloc;
return WillPopScope(
onWillPop: () {
return _deviceDetailsBloc.disconnect().then((_) {
if (deviceDetailsBloc == null) {
return Future<bool>.value(true);
}
return deviceDetailsBloc.disconnect().then((_) {
return false;
});
},
Expand All @@ -86,8 +90,10 @@ class DeviceDetailsViewState extends State<DeviceDetailsView> {
),
body: TabBarView(
children: <Widget>[
AutoTestView(_deviceDetailsBloc),
ManualTestView(_deviceDetailsBloc),
if (deviceDetailsBloc != null)
AutoTestView(deviceDetailsBloc),
if (deviceDetailsBloc != null)
ManualTestView(deviceDetailsBloc),
],
)),
),
Expand Down
Loading

0 comments on commit 1beac74

Please sign in to comment.