Skip to content

Commit 32100eb

Browse files
we-mohd-i001we-md-s001
authored andcommitted
Added: documentation comments
Added: documentation comments for invoke method Added: documentation comments for getEventStream Updated: handling of other exceptions
1 parent 30f87f1 commit 32100eb

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

lib/vaahextendflutter/services/platform_service/platform_service.dart

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'package:flutter/foundation.dart';
2+
13
import 'services/base_service.dart';
24
import 'services/platform_channel_service.dart';
35

@@ -8,10 +10,41 @@ BasePlatformService get service {
810
abstract class PlatformService {
911
static final BasePlatformService _service = service;
1012

13+
/// Invokes a [method] with or without [arguments] present at the native side.
14+
///
15+
/// Returns a [Future] which completes to one of the following:
16+
///
17+
/// * on successful invocation, a result (possibly null),
18+
/// * if the invocation failed in the platform plugin, a [PlatformException],
19+
/// * if the method has not been implemented by a platform plugin, a [MissingPluginException].
20+
///
21+
/// Example:
22+
/// ```dart
23+
/// final int sum = await PlatformService.invokeMethod<int>('getSum', {'a': 10, 'b': 20});
24+
/// print(sum); // 30
25+
/// ```
1126
static Future<T?> invokeMethod<T>(String method, [dynamic arguments]) {
1227
return _service.invokeMethod<T>(method, arguments);
1328
}
1429

30+
/// Sets up a [Stream] using the [eventChannelName] with or without [argumetns].
31+
///
32+
/// Returns a broadcast [Stream] which emits events to listeners as follows:
33+
///
34+
/// * for every successfull event, a decoded data event (possibly null) is received from the
35+
/// platform plugin;
36+
/// * for every error event, an error event containing a [PlatformException]
37+
/// received from the platform plugin.
38+
///
39+
/// When a stream is activated or deactivated, errors that happen are reported using the
40+
/// [FlutterError] capability. Only when the number of stream listeners increases from 0 to 1 does
41+
/// the stream become active. Deactivation of the stream only occurs when the number of stream
42+
/// listeners drops to zero.
43+
///
44+
/// Example:
45+
/// ```dart
46+
/// final myStream = PlatformService.getEventStream('com.example.app/battery');
47+
/// ```
1548
static Stream<dynamic> getEventStream(String eventChannelName, [dynamic arguments]) {
1649
return _service.getEventStream(eventChannelName, arguments);
1750
}

lib/vaahextendflutter/services/platform_service/services/platform_channel_service.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class PlatformChannelService implements BasePlatformService {
2020
throw 'No plugin handler for the method call was found: ${e.message}(${channel.name})';
2121
} on PlatformException catch (e) {
2222
throw 'Failed to invoke method: ${e.message}';
23+
} on Exception catch (_) {
24+
rethrow;
2325
}
2426
}
2527

0 commit comments

Comments
 (0)