Skip to content

Commit c64a882

Browse files
feat: make event interface return void
1 parent fc45417 commit c64a882

File tree

3 files changed

+24
-33
lines changed

3 files changed

+24
-33
lines changed

lib/src/countly_flutter.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,8 @@ class Countly {
411411
return message;
412412
}
413413

414-
return _instance.events.recordEvent(key, segmentation, count, sum, duration);
414+
await _instance.events.recordEvent(key, segmentation, count, sum, duration);
415+
return 'recordEvent called';
415416
}
416417

417418
static T _parseValue<T>(Map<String, Object> map, String key, T fallback) {
@@ -1680,7 +1681,8 @@ class Countly {
16801681
/// returns error or success message
16811682
@Deprecated('This function is deprecated, please use "startEvent" of events instead')
16821683
static Future<String?> startEvent(String key) async {
1683-
return _instance.events.startEvent(key);
1684+
await _instance.events.startEvent(key);
1685+
return 'startEvent called';
16841686
}
16851687

16861688
/// ends a timed event
@@ -1698,7 +1700,8 @@ class Countly {
16981700
return message;
16991701
}
17001702

1701-
return _instance.events.endEvent(key, segmentation, count, sum);
1703+
await _instance.events.endEvent(key, segmentation, count, sum);
1704+
return 'endEvent called';
17021705
}
17031706

17041707
/// Call used for testing error handling
@@ -2211,12 +2214,13 @@ class Countly {
22112214
}
22122215

22132216
/// Experimental END ---------------------------
2214-
2217+
22152218
/// Content ---------------------------
22162219
if (config.content.zoneTimerInterval != null) {
22172220
log('"_configToJson", value provided for zoneTimerInterval: [${config.content.zoneTimerInterval}]', logLevel: LogLevel.INFO);
22182221
countlyConfig['zoneTimerInterval'] = config.content.zoneTimerInterval;
22192222
}
2223+
22202224
/// Content END ---------------------------
22212225
22222226
/// APM ---------------------------

lib/src/events.dart

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,23 @@ abstract class Events {
66
/// [count]: Count to associate with the event, should be more than zero. (optional)
77
/// [sum]: Sum to associate with the event. (optional)
88
/// [duration]: Duration of the event. (optional)
9-
///
10-
/// Returns a future that resolves to the result of the operation whether success or not.
11-
Future<String?> recordEvent(String key, [Map<String, Object>? segmentation, int? count, double? sum, int? duration]);
9+
Future<void> recordEvent(String key, [Map<String, Object>? segmentation, int? count, double? sum, int? duration]);
1210

1311
/// Start timed event with a specified key
1412
///
1513
/// [key]: Name of the custom event, required, must not be an empty string.
16-
///
17-
/// Returns a future that resolves to the result of the operation whether success or not.
18-
Future<String?> startEvent(String key);
14+
Future<void> startEvent(String key);
1915

2016
/// Ends a timed event with a specified key.
2117
///
2218
/// [key]: Name of the custom event, required, must not be an empty string.
2319
/// [segmentation]: Segmentation map to associate with the event, can be null. (optional)
2420
/// [count]: Count to associate with the event, should be more than zero. Default value is 1. (optional)
2521
/// [sum]: Sum to associate with the event. Default value is 0. (optional)
26-
///
27-
/// Returns a future that resolves to the result of the operation whether success or not.
28-
Future<String?> endEvent(String key, [Map<String, Object>? segmentation, int? count, double? sum]);
22+
Future<void> endEvent(String key, [Map<String, Object>? segmentation, int? count, double? sum]);
2923

3024
/// Cancel timed event with a specified key
3125
///
3226
/// [key]: Name of the custom event, required, must not be an empty string.
33-
///
34-
/// Returns a future that resolves to the result of the operation whether success or not.
35-
Future<String?> cancelEvent(String key);
27+
Future<void> cancelEvent(String key);
3628
}

lib/src/events_internal.dart

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,36 @@ class EventsInternal implements Events {
1010
final CountlyState _countlyState;
1111

1212
@override
13-
Future<String?> recordEvent(String key, [Map<String, Object>? segmentation, int? count, double? sum, int? duration]) async {
14-
return _internalEventMethodCall(key, 'recordEvent', segmentation, count ?? 1, sum ?? 0, duration ?? 0);
13+
Future<void> recordEvent(String key, [Map<String, Object>? segmentation, int? count, double? sum, int? duration]) async {
14+
await _internalEventMethodCall(key, 'recordEvent', segmentation, count ?? 1, sum ?? 0, duration ?? 0);
1515
}
1616

1717
@override
18-
Future<String?> startEvent(String key) async {
19-
return _internalEventMethodCall(key, 'startEvent');
18+
Future<void> startEvent(String key) async {
19+
await _internalEventMethodCall(key, 'startEvent');
2020
}
2121

2222
@override
23-
Future<String?> endEvent(String key, [Map<String, Object>? segmentation, int? count, double? sum]) async {
24-
return _internalEventMethodCall(key, 'endEvent', segmentation, count ?? 1, sum ?? 0);
23+
Future<void> endEvent(String key, [Map<String, Object>? segmentation, int? count, double? sum]) async {
24+
await _internalEventMethodCall(key, 'endEvent', segmentation, count ?? 1, sum ?? 0);
2525
}
2626

2727
@override
28-
Future<String?> cancelEvent(String key) async {
29-
return _internalEventMethodCall(key, 'cancelEvent');
28+
Future<void> cancelEvent(String key) async {
29+
await _internalEventMethodCall(key, 'cancelEvent');
3030
}
3131

32-
Future<String?> _internalEventMethodCall(String key, String method, [Map<String, Object>? segmentation, int? count, double? sum, int? duration]) async {
32+
Future<void> _internalEventMethodCall(String key, String method, [Map<String, Object>? segmentation, int? count, double? sum, int? duration]) async {
3333
List<Object?> args = [];
3434

3535
if (!_countlyState.isInitialized) {
36-
String message = '"initWithConfig" must be called before "$method"';
37-
Countly.log('[EventsInternal] $method, $message', logLevel: LogLevel.ERROR);
38-
return message;
36+
Countly.log('[EventsInternal] $method, "initWithConfig" must be called', logLevel: LogLevel.ERROR);
3937
}
4038

4139
Countly.log('[EventsInternal] $method, key:[$key] segmentation:[$segmentation] count:[$count] sum:[$sum] duration:[$duration]');
4240

4341
if (key.isEmpty) {
44-
String error = '$method, key name is required';
45-
Countly.log('[EventsInternal] $method, $error');
46-
return 'Error : $error';
42+
Countly.log('[EventsInternal] $method, key name is required');
4743
}
4844

4945
args.add(key);
@@ -53,7 +49,6 @@ class EventsInternal implements Events {
5349
args.add(segmentation);
5450

5551
final String? result = await _countlyState.channel.invokeMethod(method, <String, dynamic>{'data': json.encode(args.where((item) => item != null).toList())});
56-
57-
return result;
52+
Countly.log('[EventsInternal] $method, result:[$result]');
5853
}
5954
}

0 commit comments

Comments
 (0)