Skip to content

Commit

Permalink
Merge pull request #27 from tekartik/dart3a
Browse files Browse the repository at this point in the history
Dart3a
  • Loading branch information
alextekartik authored Oct 9, 2023
2 parents 0113c5f + f3a1aca commit 3ba8d91
Show file tree
Hide file tree
Showing 66 changed files with 1,076 additions and 576 deletions.
80 changes: 80 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Dependabot configuration file.
# See https://docs.github.com/en/code-security/dependabot/dependabot-version-updates
version: 2

enable-beta-ecosystems: true
updates:
- package-ecosystem: "pub"
directory: "bluetooth"
schedule:
interval: "monthly"

- package-ecosystem: "pub"
directory: "bluetooth_bluez"
schedule:
interval: "monthly"

- package-ecosystem: "pub"
directory: "bluetooth_flutter"
schedule:
interval: "monthly"

- package-ecosystem: "pub"
directory: "bluetooth_flutter/example"
schedule:
interval: "monthly"

- package-ecosystem: "pub"
directory: "bluetooth_flutter_blue"
schedule:
interval: "monthly"

- package-ecosystem: "pub"
directory: "bluetooth_flutter_blue/example"
schedule:
interval: "monthly"

- package-ecosystem: "pub"
directory: "bluetooth_server"
schedule:
interval: "monthly"

- package-ecosystem: "pub"
directory: "bluetooth_server_app"
schedule:
interval: "monthly"

- package-ecosystem: "pub"
directory: "bluetooth_server_flutter"
schedule:
interval: "monthly"

- package-ecosystem: "pub"
directory: "bluetooth_test"
schedule:
interval: "monthly"

- package-ecosystem: "pub"
directory: "bluetooth_test_app"
schedule:
interval: "monthly"

- package-ecosystem: "pub"
directory: "bluetooth_web"
schedule:
interval: "monthly"

- package-ecosystem: "pub"
directory: "example/java_objc_app"
schedule:
interval: "monthly"

- package-ecosystem: "pub"
directory: "repo_support"
schedule:
interval: "monthly"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
5 changes: 3 additions & 2 deletions .github/workflows/run_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ jobs:
os: [ubuntu-latest, windows-latest, macos-latest]
flutter: [stable, beta]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '12.x'
- uses: subosito/flutter-action@v2
with:
Expand Down
16 changes: 0 additions & 16 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions bluetooth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ dependencies:
git:
url: https://github.com/tekartik/bluetooth.dart
path: bluetooth
ref: dart2_3
version: '>=0.2.1'
ref: dart3a
version: '>=0.6.0'
```
3 changes: 1 addition & 2 deletions bluetooth/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ linter:
rules:
- cancel_subscriptions
- hash_and_equals
- iterable_contains_unrelated_type
- list_remove_unrelated_type
- collection_methods_unrelated_type
- test_types_in_equals
- unrelated_type_equality_checks
- valid_regexps
6 changes: 6 additions & 0 deletions bluetooth/lib/bluetooth_mock.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export 'package:tekartik_bluetooth/src/mock/admin_manager_mock.dart'
show BluetoothAdminManagerMock;
export 'package:tekartik_bluetooth/src/mock/manager_mock.dart'
show BluetoothManagerMock;

export 'src/mock/peripheral_mock.dart' show BluetoothPeripheralMock;
8 changes: 8 additions & 0 deletions bluetooth/lib/bluetooth_service.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import 'package:rxdart/rxdart.dart';
import 'package:tekartik_common_utils/common_utils_import.dart';
export 'src/platform_channel.dart'
show
EventChannel,
EventChannelMixin,
MethodCall,
MethodCallMixin,
MethodChannel,
MethodChannelMixin;

/// An command object representing the invocation of a named method.
@immutable
Expand Down
1 change: 1 addition & 0 deletions bluetooth/lib/bluetooth_state_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ abstract class BluetoothStateService {
{@Deprecated('Use androidRequestCode') int? requestCode,
int? androidRequestCode});

/// No longer working on Android SDK33
Future disable();
}
2 changes: 1 addition & 1 deletion bluetooth/lib/src/bluetooth_device.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:cv/cv.dart';
import 'package:tekartik_bluetooth/src/common/device_mixin.dart';
import 'package:tekartik_bluetooth/src/device_id.dart';
import 'package:tekartik_common_utils/model/model_v2.dart';

/// Bluetooth device type.
enum BluetoothDeviceType { unknown, classic, le, dual }
Expand Down
45 changes: 42 additions & 3 deletions bluetooth/lib/src/bluetooth_peripheral.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'dart:typed_data';

import 'package:collection/collection.dart';
import 'package:cv/cv.dart';
import 'package:tekartik_bluetooth/ble.dart';
import 'package:tekartik_bluetooth/bluetooth_service.dart';
import 'package:tekartik_bluetooth/uuid.dart';
Expand Down Expand Up @@ -238,6 +240,8 @@ class BluetoothPeripheralWriteCharacteristicEvent {
Uuid128? characteristicUuid;
Uint8List? value;

BluetoothPeripheralWriteCharacteristicEvent(
{this.serviceUuid, this.characteristicUuid, this.value});
void fromMap(Map map) {
serviceUuid = Uuid128(map['service'].toString());
characteristicUuid = Uuid128(map['characteristic'].toString());
Expand All @@ -247,6 +251,27 @@ class BluetoothPeripheralWriteCharacteristicEvent {
@override
String toString() =>
'$serviceUuid $characteristicUuid ${value != null ? toHexString(value) : null}';

Model toMap() {
return Model.from({
'serviceUuid': serviceUuid?.toString(),
'characteristicUuid': characteristicUuid?.toString(),
'value': value != null ? toHexString(value) : null
});
}

@override
int get hashCode => toString().hashCode;

@override
bool operator ==(Object other) {
if (other is BluetoothPeripheralWriteCharacteristicEvent) {
return other.serviceUuid == serviceUuid &&
other.characteristicUuid == characteristicUuid &&
const ListEquality<int>().equals(other.value, value);
}
return false;
}
}

class BluetoothPeripheral {
Expand Down Expand Up @@ -311,7 +336,7 @@ class BluetoothPeripheral {

Future setCharacteristicValue(
{required Uuid128 serviceUuid,
required Uuid128? characteristicUuid,
required Uuid128 characteristicUuid,
required Uint8List? value}) async {
await _bluetoothFlutterPlugin!.methodChannel
.invokeMethod('peripheralSetCharacteristicValue', {
Expand All @@ -323,7 +348,7 @@ class BluetoothPeripheral {

Future notifyCharacteristicValue(
{required Uuid128 serviceUuid,
required Uuid128? characteristicUuid,
required Uuid128 characteristicUuid,
Uint8List? value}) async {
await _bluetoothFlutterPlugin!.methodChannel
.invokeMethod('peripheralNotifyCharacteristicValue', {
Expand All @@ -333,9 +358,23 @@ class BluetoothPeripheral {
});
}

Future setAndNotifyCharacteristicValue(
{required Uuid128 serviceUuid,
required Uuid128 characteristicUuid,
required Uint8List? value}) async {
await setCharacteristicValue(
serviceUuid: serviceUuid,
characteristicUuid: characteristicUuid,
value: value);
await notifyCharacteristicValue(
serviceUuid: serviceUuid,
characteristicUuid: characteristicUuid,
value: value);
}

Future<Uint8List> getCharacteristicValue({
required Uuid128 serviceUuid,
required Uuid128? characteristicUuid,
required Uuid128 characteristicUuid,
}) async {
var bytes = (await _bluetoothFlutterPlugin!.methodChannel
.invokeMethod('peripheralGetCharacteristicValue', {
Expand Down
2 changes: 1 addition & 1 deletion bluetooth/lib/src/common/mixin_model.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:tekartik_common_utils/model/model_v2.dart';
import 'package:cv/cv.dart';

const methodStartScan = 'startScan';
const methodStopScan = 'stopScan';
Expand Down
10 changes: 10 additions & 0 deletions bluetooth/lib/src/common/platform_mixin.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'dart:io';

import 'package:tekartik_bluetooth/src/import.dart';

mixin BluetoothManagerPlatformCompatMixin {
/// Need for all implementation for now
bool? get isAndroid => isRunningAsJavascript ? false : Platform.isAndroid;

bool? get isIOS => isRunningAsJavascript ? false : Platform.isIOS;
}
4 changes: 4 additions & 0 deletions bluetooth/lib/src/device_connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ class BluetoothDeviceConnectionState {

static const disconnected = BluetoothDeviceConnectionState(
bluetoothDeviceConnectionStateDisconnected);

/// No longer supported on Android and iOS
static const connecting =
BluetoothDeviceConnectionState(bluetoothDeviceConnectionStateConnecting);
static const connected =
BluetoothDeviceConnectionState(bluetoothDeviceConnectionStateConnected);

/// No longer supported on Android and iOS
static const disconnecting = BluetoothDeviceConnectionState(
bluetoothDeviceConnectionStateDisconnecting);
static const unknown =
Expand Down
2 changes: 1 addition & 1 deletion bluetooth/lib/src/device_id.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ abstract class BluetoothDeviceId {
factory BluetoothDeviceId(String id) => BluetoothDeviceIdImpl(id);
}

abstract class BluetoothDeviceIdMixin implements BluetoothDeviceId {
abstract mixin class BluetoothDeviceIdMixin implements BluetoothDeviceId {
@override
int get hashCode => id.toLowerCase().hashCode;

Expand Down
27 changes: 25 additions & 2 deletions bluetooth/lib/src/info.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:cv/cv.dart';
import 'package:tekartik_common_utils/bool_utils.dart';
import 'package:tekartik_common_utils/model/model_v2.dart';

abstract class BluetoothInfo {
bool? get hasBluetooth;
Expand Down Expand Up @@ -34,7 +34,10 @@ class BluetoothInfoImpl implements BluetoothInfo {
bool? isScanning;

BluetoothInfoImpl(
{this.hasBluetooth, this.hasBluetoothBle, this.isBluetoothEnabled});
{this.hasBluetooth,
this.hasBluetoothBle,
this.isBluetoothEnabled,
this.isScanning});

void fromMap(Map result) {
var model = asModel(result);
Expand Down Expand Up @@ -87,4 +90,24 @@ class BluetoothAdminInfoImpl implements BluetoothAdminInfo {
..setValue('isBluetoothEnabled', isBluetoothEnabled);
return model;
}

@override
int get hashCode => toString().hashCode;

@override
bool operator ==(Object other) {
if (other is BluetoothAdminInfoImpl) {
if (other.hasBluetooth != hasBluetooth) {
return false;
}
if (other.hasBluetoothBle != hasBluetoothBle) {
return false;
}
if (other.isBluetoothEnabled != isBluetoothEnabled) {
return false;
}
return true;
}
return false;
}
}
40 changes: 40 additions & 0 deletions bluetooth/lib/src/mock/admin_manager_mock.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'package:tekartik_bluetooth/bluetooth.dart';
import 'package:tekartik_bluetooth/src/common/platform_mixin.dart';
import 'package:tekartik_bluetooth/src/import.dart';
import 'package:tekartik_bluetooth/src/mixin.dart';

class BluetoothAdminManagerMock
with BluetoothAdminManagerMixin, BluetoothManagerPlatformCompatMixin
implements BluetoothAdminManager {
@override
Future<bool> checkCoarseLocationPermission({int? androidRequestCode}) async {
return true;
}

@override
Future<bool> checkBluetoothPermissions(
{int? androidRequestCode, BluetoothPermissionsOptions? options}) async {
return true;
}

@override
Future disable() async {}

@override
Future enable({int? requestCode, int? androidRequestCode}) async {}

@override
Future<T> invokeMethod<T>(String method, [Object? arguments]) {
// TODO: implement invokeMethod
throw UnimplementedError();
}

@override
bool? get supportsEnable => false;

@override
Future<BluetoothAdminInfo> getAdminInfo() async {
return BluetoothAdminInfoImpl(
hasBluetooth: true, hasBluetoothBle: true, isBluetoothEnabled: true);
}
}
Loading

0 comments on commit 3ba8d91

Please sign in to comment.