Skip to content

Commit 5897ec4

Browse files
committed
feat return a boolean indicating whether the [data] was successfully sent using the [shareData] method
doc improve documentation for [shareData] method feat return the original Future from the [disposeOverlayListener] method
1 parent c0f2bbc commit 5897ec4

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

lib/src/overlay_window.dart

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

4+
import 'package:flutter/material.dart';
45
import 'package:flutter/services.dart';
56
import 'package:flutter_overlay_window/src/overlay_config.dart';
67

@@ -81,9 +82,32 @@ class FlutterOverlayWindow {
8182
return _res;
8283
}
8384

84-
/// Broadcast data to and from overlay app
85-
static Future shareData(dynamic data) async {
86-
return await _overlayMessageChannel.send(data);
85+
/// Broadcast [data] to and from overlay app.
86+
///
87+
/// If `true` is returned, it indicates that the [data] was sent. However, this doesn't mean
88+
/// that the [data] has already reached the listeners of the [overlayListener] stream.
89+
///
90+
/// If `false` is returned, it indicates that the [data] was not sent.
91+
///
92+
/// This method may return `false` under the following conditions:
93+
/// - The overlay is closed.
94+
/// - The application is detached from the activity, i.e. the application is closed.
95+
///
96+
/// Returns `true` if the [data] was sent successfully, otherwise `false`.
97+
///
98+
/// May return `null`, indicating a failure to send the [data] (This is unexpected behavior,
99+
/// and if encountered, indicates a bug within plugin implementation that should be addressed).
100+
static Future<bool?> shareData(dynamic data) async {
101+
final isSent = await _overlayMessageChannel.send(data);
102+
if (isSent == null) {
103+
debugPrintStack(
104+
stackTrace: StackTrace.current,
105+
label: "[FlutterOverlayWindow] ERROR: "
106+
"Failed to send the [data] using the [shareData] method. "
107+
"Message channel handler is not registered.");
108+
return null;
109+
}
110+
return isSent as bool;
87111
}
88112

89113
/// Streams message shared between overlay and main app
@@ -123,7 +147,7 @@ class FlutterOverlayWindow {
123147
/// Dispose overlay stream.
124148
///
125149
/// Once disposed, only a complete restart of the application will re-initialize the listener.
126-
static void disposeOverlayListener() {
127-
_controller.close();
150+
static Future<dynamic> disposeOverlayListener() {
151+
return _controller.close();
128152
}
129153
}

0 commit comments

Comments
 (0)