From 0dbbe42f2e49fbb88dda3e65bb58beeadd51f4e7 Mon Sep 17 00:00:00 2001 From: TalebRafiepour Date: Thu, 3 Nov 2022 11:57:07 +0330 Subject: [PATCH] send beacon connection error from Kotlin to Flutter --- .../src/main/kotlin/io/altme/beacon/beacon/BeaconPlugin.kt | 1 + example/lib/main.dart | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/android/src/main/kotlin/io/altme/beacon/beacon/BeaconPlugin.kt b/android/src/main/kotlin/io/altme/beacon/beacon/BeaconPlugin.kt index 68adfcf..3f9f2c6 100644 --- a/android/src/main/kotlin/io/altme/beacon/beacon/BeaconPlugin.kt +++ b/android/src/main/kotlin/io/altme/beacon/beacon/BeaconPlugin.kt @@ -275,6 +275,7 @@ class BeaconPlugin : MethodChannel.MethodCallHandler, EventChannel.StreamHandler beaconClient?.connect() ?.catch { error -> Log.e(tag, "connect: ${error.message}") + result.success(mapOf("failure" to error.message)) } ?.onEach { result -> result.getOrNull()?.let { saveAwaitingRequest(it) } } ?.collect { result -> diff --git a/example/lib/main.dart b/example/lib/main.dart index 5ada3f7..d16ae01 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -53,6 +53,11 @@ class _MyHomePageState extends State { startBeacon() async { final Map response = await _beaconPlugin.startBeacon(walletName: "Altme Wallet"); + if (response['failure'] != null) { + final fauilure = json.decode(response['failure'].toString()); + print('fauilure: $fauilure'); + return; + } setState(() { hasPeers = json.decode(response['success'].toString()); });