Skip to content

Commit 3ce12d7

Browse files
authored
Merge pull request #136 from fiqihnurramadhan/main
Add Future return in some methods
2 parents dda954d + 9afc682 commit 3ce12d7

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

lib/mixpanel_flutter.dart

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import 'dart:async';
2-
import 'package:flutter/services.dart';
32
import 'dart:developer' as developer;
43
import 'dart:io' show Platform;
4+
55
import 'package:flutter/foundation.dart' show kIsWeb;
6+
import 'package:flutter/services.dart';
67
import 'package:mixpanel_flutter/codec/mixpanel_message_codec.dart';
78

89
/// The primary class for integrating Mixpanel with your app.
@@ -145,9 +146,9 @@ class Mixpanel {
145146
/// Mixpanel using the same disinct_id will be considered associated with the
146147
/// same visitor/customer for retention and funnel reporting, so be sure that the given
147148
/// value is globally unique for each individual user you intend to track.
148-
void identify(String distinctId) {
149+
Future<void> identify(String distinctId) async {
149150
if (_MixpanelHelper.isValidString(distinctId)) {
150-
_channel.invokeMethod<void>(
151+
await _channel.invokeMethod<void>(
151152
'identify', <String, dynamic>{'distinctId': distinctId});
152153
} else {
153154
developer.log('`identify` failed: distinctId cannot be blank',
@@ -189,9 +190,12 @@ class Mixpanel {
189190
///
190191
/// * [eventName] The name of the event to send
191192
/// * [properties] An optional map containing the key value pairs of the properties to include in this event.
192-
void track(String eventName, {Map<String, dynamic>? properties}) {
193+
Future<void> track(
194+
String eventName, {
195+
Map<String, dynamic>? properties,
196+
}) async {
193197
if (_MixpanelHelper.isValidString(eventName)) {
194-
_channel.invokeMethod<void>('track',
198+
await _channel.invokeMethod<void>('track',
195199
<String, dynamic>{'eventName': eventName, 'properties': properties});
196200
} else {
197201
developer.log('`track` failed: eventName cannot be blank',
@@ -217,10 +221,13 @@ class Mixpanel {
217221
/// * [eventName] The name of the event to send
218222
/// * [properties] A Map containing the key value pairs of the properties to include in this event.
219223
/// * [groups] A Map containing the group key value pairs for this event.
220-
void trackWithGroups(String eventName, Map<String, dynamic> properties,
221-
Map<String, dynamic> groups) {
224+
Future<void> trackWithGroups(
225+
String eventName,
226+
Map<String, dynamic> properties,
227+
Map<String, dynamic> groups,
228+
) async {
222229
if (_MixpanelHelper.isValidString(eventName)) {
223-
_channel.invokeMethod<void>('trackWithGroups', <String, dynamic>{
230+
await _channel.invokeMethod<void>('trackWithGroups', <String, dynamic>{
224231
'eventName': eventName,
225232
'properties': properties,
226233
'groups': groups
@@ -314,8 +321,8 @@ class Mixpanel {
314321
/// to remove a superProperty, call unregisterSuperProperty() or clearSuperProperties()
315322
///
316323
/// * [properties] A Map containing super properties to register
317-
void registerSuperProperties(Map<String, dynamic> properties) {
318-
_channel.invokeMethod<void>(
324+
Future<void> registerSuperProperties(Map<String, dynamic> properties) async {
325+
await _channel.invokeMethod<void>(
319326
'registerSuperProperties', <String, dynamic>{'properties': properties});
320327
}
321328

@@ -325,8 +332,10 @@ class Mixpanel {
325332
/// Calling registerSuperPropertiesOnce will never overwrite existing properties.
326333
///
327334
/// * [properties] A Map containing the super properties to register.
328-
void registerSuperPropertiesOnce(Map<String, dynamic> properties) {
329-
_channel.invokeMethod<void>('registerSuperPropertiesOnce',
335+
Future<void> registerSuperPropertiesOnce(
336+
Map<String, dynamic> properties,
337+
) async {
338+
await _channel.invokeMethod<void>('registerSuperPropertiesOnce',
330339
<String, dynamic>{'properties': properties});
331340
}
332341

@@ -337,9 +346,9 @@ class Mixpanel {
337346
/// To clear all superProperties, use clearSuperProperties()
338347
///
339348
/// * [propertyName] name of the property to unregister
340-
void unregisterSuperProperty(String propertyName) {
349+
Future<void> unregisterSuperProperty(String propertyName) async {
341350
if (_MixpanelHelper.isValidString(propertyName)) {
342-
_channel.invokeMethod<void>('unregisterSuperProperty',
351+
await _channel.invokeMethod<void>('unregisterSuperProperty',
343352
<String, dynamic>{'propertyName': propertyName});
344353
} else {
345354
developer.log(
@@ -364,8 +373,8 @@ class Mixpanel {
364373
/// superProperties registered before the clearSuperProperties method was called.
365374
///
366375
/// To remove a single superProperty, use unregisterSuperProperty()
367-
void clearSuperProperties() {
368-
_channel.invokeMethod<void>('clearSuperProperties');
376+
Future<void> clearSuperProperties() async {
377+
await _channel.invokeMethod<void>('clearSuperProperties');
369378
}
370379

371380
/// Begin timing of an event. Calling timeEvent("Thing") will not send an event, but
@@ -399,8 +408,8 @@ class Mixpanel {
399408

400409
/// Clear super properties and generates a new random distinctId for this instance.
401410
/// Useful for clearing data when a user logs out.
402-
void reset() {
403-
_channel.invokeMethod<void>('reset');
411+
Future<void> reset() async {
412+
await _channel.invokeMethod<void>('reset');
404413
}
405414

406415
/// Returns the current distinct id of the user.

0 commit comments

Comments
 (0)