From 514cd40dc6a1069101fa66cd9df6a37af489ad21 Mon Sep 17 00:00:00 2001 From: o-bagge <47336932+o-bagge@users.noreply.github.com> Date: Fri, 2 Jan 2026 16:55:53 +0100 Subject: [PATCH] Revert "update device connection exceptions" --- example/lib/main.dart | 31 +++--------------------- example/pubspec.lock | 24 ++++++------------ example/pubspec.yaml | 1 - lib/open_earable_flutter.dart | 26 ++++---------------- lib/src/exceptions/device_exception.dart | 15 ------------ 5 files changed, 17 insertions(+), 80 deletions(-) delete mode 100644 lib/src/exceptions/device_exception.dart diff --git a/example/lib/main.dart b/example/lib/main.dart index d33bf6b..fc19a96 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -2,7 +2,6 @@ import 'dart:async'; import 'package:example/widgets/button_state_widget.dart'; import 'package:example/widgets/fota/firmware_update.dart'; -import 'package:flutter_platform_widgets/flutter_platform_widgets.dart'; import 'package:open_earable_flutter/open_earable_flutter.dart'; import 'package:example/global_theme.dart'; import 'package:flutter/material.dart'; @@ -153,30 +152,9 @@ class MyAppState extends State { trailing: _buildTrailingWidget(device.id, Theme.of(context).colorScheme.secondary), onTap: () async { - try { - Wearable wearable = await _wearableManager - .connectToDevice(device); - provider.setSelectedPeripheral(wearable); - } catch (e) { - String message = _wearableManager - .deviceErrorMessage(e, device.name); - if (context.mounted) { - showPlatformDialog( - context: context, - builder: (context) => PlatformAlertDialog( - title: PlatformText('Connection Error'), - content: PlatformText(message), - actions: [ - PlatformDialogAction( - onPressed: () => - Navigator.of(context).pop(), - child: PlatformText('OK'), - ), - ], - ), - ); - } - } + Wearable wearable = await _wearableManager + .connectToDevice(device); + provider.setSelectedPeripheral(wearable); }, ), if (index != discoveredDevices.length - 1) @@ -268,8 +246,7 @@ class MyAppState extends State { if (_connectedDevice is ButtonManager) GroupedBox( title: "Button State", - child: ButtonStateWidget( - buttonManager: _connectedDevice as ButtonManager), + child: ButtonStateWidget(buttonManager: _connectedDevice as ButtonManager), ), if (_connectedDevice is FrequencyPlayer) GroupedBox( diff --git a/example/pubspec.lock b/example/pubspec.lock index 231d77d..dc169aa 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -45,10 +45,10 @@ packages: dependency: transitive description: name: characters - sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b + sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803 url: "https://pub.dev" source: hosted - version: "1.4.1" + version: "1.4.0" clock: dependency: transitive description: @@ -182,14 +182,6 @@ packages: url: "https://pub.dev" source: hosted version: "6.0.0" - flutter_platform_widgets: - dependency: "direct main" - description: - name: flutter_platform_widgets - sha256: "22a86564cb6cc0b93637c813ca91b0b1f61c2681a31e0f9d77590c1fa9f12020" - url: "https://pub.dev" - source: hosted - version: "9.0.0" flutter_plugin_android_lifecycle: dependency: transitive description: @@ -300,18 +292,18 @@ packages: dependency: transitive description: name: matcher - sha256: "12956d0ad8390bbcc63ca2e1469c0619946ccb52809807067a7020d57e647aa6" + sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2 url: "https://pub.dev" source: hosted - version: "0.12.18" + version: "0.12.17" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b" + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted - version: "0.13.0" + version: "0.11.1" mcumgr_flutter: dependency: "direct main" description: @@ -568,10 +560,10 @@ packages: dependency: transitive description: name: test_api - sha256: "19a78f63e83d3a61f00826d09bc2f60e191bf3504183c001262be6ac75589fb8" + sha256: ab2726c1a94d3176a45960b6234466ec367179b87dd74f1611adb1f3b5fb9d55 url: "https://pub.dev" source: hosted - version: "0.7.8" + version: "0.7.7" tuple: dependency: transitive description: diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 2f208cc..a3e5773 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -42,7 +42,6 @@ dependencies: # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 flutter_colorpicker: ^1.1.0 - flutter_platform_widgets: ^9.0.0 meta: ^1.16.0 bloc: ^9.1.0 flutter_svg: ^2.0.17 diff --git a/lib/open_earable_flutter.dart b/lib/open_earable_flutter.dart index b357438..48bb10f 100644 --- a/lib/open_earable_flutter.dart +++ b/lib/open_earable_flutter.dart @@ -4,7 +4,6 @@ import 'dart:async'; import 'package:logger/logger.dart'; import 'package:meta/meta.dart'; -import 'package:open_earable_flutter/src/exceptions/device_exception.dart'; import 'package:open_earable_flutter/src/models/devices/cosinuss_one_factory.dart'; import 'package:open_earable_flutter/src/models/devices/esense_factory.dart'; import 'package:open_earable_flutter/src/models/devices/open_earable_factory.dart'; @@ -194,7 +193,7 @@ class WearableManager { }) async { if (_connectedIds.contains(device.id)) { logger.w('Device ${device.id} is already connected'); - throw AlreadyConnectedException(); + throw Exception('Device is already connected'); } _connectingStreamController.add(device); @@ -227,9 +226,9 @@ class WearableManager { } _connectedIds.remove(device.id); await _bleManager.disconnect(device.id); - throw UnsupportedDeviceException(); + throw Exception('Device is currently not supported'); } else { - throw ConnectionFailedException(); + throw Exception('Failed to connect to device'); } } @@ -253,25 +252,12 @@ class WearableManager { ); connectedWearables.add(wearable); } catch (e) { - logger.e( - 'Failed to connect to system device ${device.id}: ${deviceErrorMessage(e, device.name)}', - ); + logger.e('Failed to connect to system device ${device.id}: $e'); } } return connectedWearables; } - String deviceErrorMessage(dynamic e, String deviceName) { - return switch (e) { - UnsupportedDeviceException _ => 'Device "$deviceName" is not supported.', - AlreadyConnectedException _ => - 'Device "$deviceName" is already connected.', - ConnectionFailedException _ => - 'Failed to connect to device "$deviceName". Please try again.', - _ => e.toString(), - }; - } - void addPairingRule(PairingRule rule) { _pairingManager.addRule(rule); } @@ -306,9 +292,7 @@ class WearableManager { try { await connectToDevice(discoveredDevice); } catch (e) { - logger.e( - 'Error auto connecting device ${discoveredDevice.id}: ${deviceErrorMessage(e, discoveredDevice.name)}', - ); + logger.e('Error auto connecting device ${discoveredDevice.id}: $e'); } } }); diff --git a/lib/src/exceptions/device_exception.dart b/lib/src/exceptions/device_exception.dart deleted file mode 100644 index f409352..0000000 --- a/lib/src/exceptions/device_exception.dart +++ /dev/null @@ -1,15 +0,0 @@ -sealed class DeviceException implements Exception { - const DeviceException(); -} - -class UnsupportedDeviceException extends DeviceException { - const UnsupportedDeviceException(); -} - -class AlreadyConnectedException extends DeviceException { - const AlreadyConnectedException(); -} - -class ConnectionFailedException extends DeviceException { - const ConnectionFailedException(); -}