Skip to content

Commit b6ed17a

Browse files
authored
Merge pull request #18 from dotintent/fix/release
0.0.3 release
2 parents 7d6c2f4 + 625006d commit b6ed17a

7 files changed

Lines changed: 1106 additions & 2476 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.0.3
2+
3+
* Migration to dart:ffi
4+
* Add support for WiFi
5+
16
## 0.0.2
27

38
* Minor readme updates

lib/flutter_accessorysetup.dart

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dart:async';
22

3+
import 'package:flutter/foundation.dart';
34
import 'package:objective_c/objective_c.dart';
45
import 'package:flutter/services.dart';
56

@@ -35,8 +36,7 @@ class FlutterAccessorySetup {
3536
}) {
3637
_convertToNSArray = listConverter ?? (list) => list.toNSArray();
3738
_convertToNativeCodeError = nsErrorConverter ?? (nsError) => NativeCodeError(nsError);
38-
_sessionAdapter = sessionAdapter ??
39-
FFIAccessorySessionAdapter(FFIAccessorySession.alloc().init());
39+
_sessionAdapter = sessionAdapter ?? FFIAccessorySessionAdapter(FFIAccessorySession.alloc().init());
4040
_delegateAdapter = delegateAdapterFactory(
4141
handleEvent: _handleEvent,
4242
didShowPickerWithError: _didShowPicker,
@@ -82,29 +82,23 @@ class FlutterAccessorySetup {
8282
/// - name: the name of the device to display in picker
8383
/// - asset: the asset of the device image to display in picker
8484
/// - serviceID: the service UUID advertised by device (to search for a particular device)
85-
Future<void> showPickerForDevice(
86-
String name, String asset, String serviceID) async {
85+
Future<void> showPickerForDevice(String name, String asset, String serviceID) async {
8786
final completer = Completer<void>();
8887
_showPickerCompleter = completer;
8988

9089
final image = await nativeUIImageWithDartAsset(asset);
9190
if (image == null) {
92-
throw FlutterAccessorysetupError(
93-
code: 1, description: "Failed to load UIImage for the asset: $asset");
91+
throw FlutterAccessorysetupError(code: 1, description: "Failed to load UIImage for the asset: $asset");
9492
}
9593
final descriptor = ASDiscoveryDescriptor.alloc().init();
96-
descriptor.bluetoothServiceUUID =
97-
CBUUID.UUIDWithString_(serviceID.toNSString());
98-
final item = ASPickerDisplayItem.alloc()
99-
.initWithName_productImage_descriptor_(
100-
name.toNSString(), image, descriptor);
94+
descriptor.bluetoothServiceUUID = CBUUID.UUIDWithString_(serviceID.toNSString());
95+
final item = ASPickerDisplayItem.alloc().initWithName_productImage_descriptor_(name.toNSString(), image, descriptor);
10196
_sessionAdapter.showPickerForItems_(_convertToNSArray([item]));
10297
return completer.future;
10398
}
10499

105100
/// Renames provided accessory using the `ASAccessoryRenameOptions`
106-
Future<void> renameAccessory(
107-
ASAccessory accessory, ASAccessoryRenameOptions options) async {
101+
Future<void> renameAccessory(ASAccessory accessory, ASAccessoryRenameOptions options) async {
108102
final completer = Completer<void>();
109103
_renameAccessoryCompleter = completer;
110104
_sessionAdapter.renameAccessory_options_(accessory, options);
@@ -120,12 +114,10 @@ class FlutterAccessorySetup {
120114
}
121115

122116
/// Finishes the Authorization for accessory using `ASAccessorySettings`
123-
Future<void> finishAuthorizationForAccessory(
124-
ASAccessory accessory, ASAccessorySettings settings) async {
117+
Future<void> finishAuthorizationForAccessory(ASAccessory accessory, ASAccessorySettings settings) async {
125118
final completer = Completer<void>();
126119
_finishAuthorizationForAccessoryCompleter = completer;
127-
_sessionAdapter.finishAuthorizationForAccessory_settings_(
128-
accessory, settings);
120+
_sessionAdapter.finishAuthorizationForAccessory_settings_(accessory, settings);
129121
return completer.future;
130122
}
131123

@@ -171,17 +163,15 @@ class FlutterAccessorySetup {
171163

172164
void _didFinishAuthorization(ASAccessory accessory, NSError? nsError) {
173165
if (nsError != null) {
174-
_finishAuthorizationForAccessoryCompleter
175-
?.completeError(_convertToNativeCodeError(nsError));
166+
_finishAuthorizationForAccessoryCompleter?.completeError(_convertToNativeCodeError(nsError));
176167
return;
177168
}
178169
_finishAuthorizationForAccessoryCompleter?.complete();
179170
}
180171

181172
void _didFailAuthorization(ASAccessory accessory, NSError? nsError) {
182173
if (nsError != null) {
183-
_failAuthorizationForAccessoryCompleter
184-
?.completeError(_convertToNativeCodeError(nsError));
174+
_failAuthorizationForAccessoryCompleter?.completeError(_convertToNativeCodeError(nsError));
185175
return;
186176
}
187177
_failAuthorizationForAccessoryCompleter?.complete();
@@ -195,9 +185,9 @@ class FlutterAccessorySetup {
195185
/// Use it for debugging the native part of the code
196186
void printNativeSessionLogs() {
197187
final logs = _sessionAdapter.logs.toDartStringList();
198-
print("logs count: ${logs.length}");
188+
debugPrint("logs count: ${logs.length}");
199189
for (final log in logs) {
200-
print(log);
190+
debugPrint(log);
201191
}
202192
}
203193

@@ -218,8 +208,7 @@ class FlutterAccessorysetupError extends Error {
218208
FlutterAccessorysetupError({required this.code, required this.description});
219209

220210
@override
221-
String toString() =>
222-
'FlutterAccessorysetupError(code: $code, description: $description)';
211+
String toString() => 'FlutterAccessorysetupError(code: $code, description: $description)';
223212
}
224213

225214
/// The class for errors occurred in the Native code of the library
@@ -235,8 +224,7 @@ class NativeCodeError extends Error {
235224
}
236225

237226
@override
238-
String toString() =>
239-
'NativeCodeError(domain: $domain, code: $code, description: $description)';
227+
String toString() => 'NativeCodeError(domain: $domain, code: $code, description: $description)';
240228
}
241229

242230
/// Exposing native properties as Dart types

0 commit comments

Comments
 (0)