Skip to content

Commit

Permalink
pr suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
mrehan27 committed Nov 28, 2024
1 parent c383f2e commit ead4383
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 70 deletions.
16 changes: 8 additions & 8 deletions lib/customer_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class CustomerIO {
///
/// @param userId unique identifier for a profile
/// @param traits (Optional) params to set profile attributes
Future<void> identify(
void identify(
{required String userId, Map<String, dynamic> traits = const {}}) {
return _platform.identify(
userId: userId, traits: traits.excludeNullValues());
Expand All @@ -101,7 +101,7 @@ class CustomerIO {
///
/// If a profile exists, clearIdentify will stop identifying the profile.
/// If no profile exists, request to clearIdentify will be ignored.
Future<void> clearIdentify() {
void clearIdentify() {
return _platform.clearIdentify();
}

Expand All @@ -110,14 +110,14 @@ class CustomerIO {
///
/// @param name event name to be tracked
/// @param properties (Optional) params to be sent with event
Future<void> track(
void track(
{required String name, Map<String, dynamic> properties = const {}}) {
return _platform.track(
name: name, properties: properties.excludeNullValues());
}

/// Track a push metric
Future<void> trackMetric(
void trackMetric(
{required String deliveryID,
required String deviceToken,
required MetricEvent event}) {
Expand All @@ -127,15 +127,15 @@ class CustomerIO {

/// Register a new device token with Customer.io, associated with the current active customer. If there
/// is no active customer, this will fail to register the device
Future<void> registerDeviceToken({required String deviceToken}) {
void registerDeviceToken({required String deviceToken}) {
return _platform.registerDeviceToken(deviceToken: deviceToken);
}

/// Track screen events to record the screens a user visits
///
/// @param name name of the screen user visited
/// @param attributes (Optional) params to be sent with event
Future<void> screen(
void screen(
{required String title, Map<String, dynamic> properties = const {}}) {
return _platform.screen(
title: title, properties: properties.excludeNullValues());
Expand All @@ -145,15 +145,15 @@ class CustomerIO {
/// such as app preferences, timezone etc
///
/// @param attributes device attributes
Future<void> setDeviceAttributes({required Map<String, dynamic> attributes}) {
void setDeviceAttributes({required Map<String, dynamic> attributes}) {
return _platform.setDeviceAttributes(attributes: attributes);
}

/// Set custom user profile information such as user preference, specific
/// user actions etc
///
/// @param attributes additional attributes for a user profile
Future<void> setProfileAttributes(
void setProfileAttributes(
{required Map<String, dynamic> attributes}) {
return _platform.setProfileAttributes(
attributes: attributes.excludeNullValues());
Expand Down
18 changes: 9 additions & 9 deletions lib/data_pipelines/customer_io_method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CustomerIOMethodChannel extends CustomerIOPlatform {
/// To initialize the plugin
@override
Future<void> initialize({required CustomerIOConfig config}) {
return methodChannel.invokeNativeMethodVoid(
return methodChannel.invokeNativeMethod<void>(
NativeMethods.initialize, config.toMap());
}

Expand All @@ -27,7 +27,7 @@ class CustomerIOMethodChannel extends CustomerIOPlatform {
/// identifiers are attempted to be identified, then the last identified profile
/// will be removed automatically.
@override
Future<void> identify(
void identify(
{required String userId, Map<String, dynamic> traits = const {}}) {
return methodChannel.invokeNativeMethodVoid(NativeMethods.identify, {
NativeMethodParams.userId: userId,
Expand All @@ -38,7 +38,7 @@ class CustomerIOMethodChannel extends CustomerIOPlatform {
/// To track user events like loggedIn, addedItemToCart etc.
/// You may also track events with additional yet optional data.
@override
Future<void> track(
void track(
{required String name, Map<String, dynamic> properties = const {}}) {
return methodChannel.invokeNativeMethodVoid(NativeMethods.track, {
NativeMethodParams.name: name,
Expand All @@ -48,7 +48,7 @@ class CustomerIOMethodChannel extends CustomerIOPlatform {

/// Track a push metric
@override
Future<void> trackMetric(
void trackMetric(
{required String deliveryID,
required String deviceToken,
required MetricEvent event}) {
Expand All @@ -61,7 +61,7 @@ class CustomerIOMethodChannel extends CustomerIOPlatform {

/// Track screen events to record the screens a user visits
@override
Future<void> screen(
void screen(
{required String title, Map<String, dynamic> properties = const {}}) {
return methodChannel.invokeNativeMethodVoid(NativeMethods.screen, {
NativeMethodParams.title: title,
Expand All @@ -72,7 +72,7 @@ class CustomerIOMethodChannel extends CustomerIOPlatform {
/// Register a new device token with Customer.io, associated with the current active customer. If there
/// is no active customer, this will fail to register the device
@override
Future<void> registerDeviceToken({required String deviceToken}) {
void registerDeviceToken({required String deviceToken}) {
return methodChannel
.invokeNativeMethodVoid(NativeMethods.registerDeviceToken, {
NativeMethodParams.token: deviceToken,
Expand All @@ -81,14 +81,14 @@ class CustomerIOMethodChannel extends CustomerIOPlatform {

/// Call this function to stop identifying a person.
@override
Future<void> clearIdentify() {
void clearIdentify() {
return methodChannel.invokeNativeMethodVoid(NativeMethods.clearIdentify);
}

/// Set custom user profile information such as user preference, specific
/// user actions etc
@override
Future<void> setProfileAttributes(
void setProfileAttributes(
{required Map<String, dynamic> attributes}) {
return methodChannel
.invokeNativeMethodVoid(NativeMethods.setProfileAttributes, {
Expand All @@ -99,7 +99,7 @@ class CustomerIOMethodChannel extends CustomerIOPlatform {
/// Use this function to send custom device attributes
/// such as app preferences, timezone etc
@override
Future<void> setDeviceAttributes({required Map<String, dynamic> attributes}) {
void setDeviceAttributes({required Map<String, dynamic> attributes}) {
return methodChannel
.invokeNativeMethodVoid(NativeMethods.setDeviceAttributes, {
NativeMethodParams.attributes: attributes,
Expand Down
16 changes: 8 additions & 8 deletions lib/data_pipelines/customer_io_platform_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,41 +33,41 @@ abstract class CustomerIOPlatform extends PlatformInterface {
throw UnimplementedError('initialize() has not been implemented.');
}

Future<void> identify(
void identify(
{required String userId, Map<String, dynamic> traits = const {}}) {
throw UnimplementedError('identify() has not been implemented.');
}

Future<void> clearIdentify() {
void clearIdentify() {
throw UnimplementedError('clearIdentify() has not been implemented.');
}

Future<void> track(
void track(
{required String name, Map<String, dynamic> properties = const {}}) {
throw UnimplementedError('track() has not been implemented.');
}

Future<void> trackMetric(
void trackMetric(
{required String deliveryID,
required String deviceToken,
required MetricEvent event}) {
throw UnimplementedError('trackMetric() has not been implemented.');
}

Future<void> registerDeviceToken({required String deviceToken}) {
void registerDeviceToken({required String deviceToken}) {
throw UnimplementedError('registerDeviceToken() has not been implemented.');
}

Future<void> screen(
void screen(
{required String title, Map<String, dynamic> properties = const {}}) {
throw UnimplementedError('screen() has not been implemented.');
}

Future<void> setDeviceAttributes({required Map<String, dynamic> attributes}) {
void setDeviceAttributes({required Map<String, dynamic> attributes}) {
throw UnimplementedError('setDeviceAttributes() has not been implemented.');
}

Future<void> setProfileAttributes(
void setProfileAttributes(
{required Map<String, dynamic> attributes}) {
throw UnimplementedError(
'setProfileAttributes() has not been implemented.');
Expand Down
6 changes: 3 additions & 3 deletions lib/extensions/method_channel_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ extension CustomerIOMethodChannelExtensions on MethodChannel {
}

/// Simplifies invoking a native method that doesn't return a value.
Future<void> invokeNativeMethodVoid(String method,
[Map<String, dynamic> arguments = const {}]) async {
return await invokeNativeMethod<void>(method, arguments);
void invokeNativeMethodVoid(String method,
[Map<String, dynamic> arguments = const {}]) {
invokeNativeMethod<void>(method, arguments);
}
}
2 changes: 1 addition & 1 deletion lib/messaging_in_app/method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CustomerIOMessagingInAppMethodChannel
final _inAppEventStreamController = StreamController<InAppEvent>.broadcast();

@override
Future<void> dismissMessage() {
void dismissMessage() {
return methodChannel.invokeNativeMethodVoid(NativeMethods.dismissMessage);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/messaging_in_app/platform_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract class CustomerIOMessagingInAppPlatform extends PlatformInterface {
_instance = instance;
}

Future<void> dismissMessage() {
void dismissMessage() {
throw UnimplementedError('dismissMessage() has not been implemented.');
}

Expand Down
4 changes: 2 additions & 2 deletions test/customer_io_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ void main() {
await CustomerIO.initialize(config: config);
});

test('identify() calls platform', () async {
test('identify() calls platform', () {
const givenIdentifier = '[email protected]';
final givenAttributes = {'name': 'John Doe'};
await CustomerIO.instance.identify(
CustomerIO.instance.identify(
userId: givenIdentifier,
traits: givenAttributes,
);
Expand Down
66 changes: 28 additions & 38 deletions test/customer_io_test.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import 'customer_io_test.dart' as _i3;
class _FakeStreamSubscription_0<T> extends _i1.SmartFake
implements _i2.StreamSubscription<T> {
_FakeStreamSubscription_0(
Object parent,
Invocation parentInvocation,
) : super(
parent,
parentInvocation,
);
Object parent,
Invocation parentInvocation,
) : super(
parent,
parentInvocation,
);
}

/// A class which mocks [TestCustomerIoPlatform].
Expand All @@ -55,7 +55,7 @@ class MockTestCustomerIoPlatform extends _i1.Mock
returnValueForMissingStub: _i2.Future<void>.value(),
) as _i2.Future<void>);
@override
_i2.Future<void> identify({
void identify({
required String? userId,
Map<String, dynamic>? traits = const {},
}) =>
Expand All @@ -68,20 +68,18 @@ class MockTestCustomerIoPlatform extends _i1.Mock
#traits: traits,
},
),
returnValue: _i2.Future<void>.value(),
returnValueForMissingStub: _i2.Future<void>.value(),
returnValueForMissingStub: null,
);
@override
_i2.Future<void> clearIdentify() => super.noSuchMethod(
Invocation.method(
#clearIdentify,
[],
),
returnValue: _i2.Future<void>.value(),
returnValueForMissingStub: _i2.Future<void>.value(),
);
void clearIdentify() => super.noSuchMethod(
Invocation.method(
#clearIdentify,
[],
),
returnValueForMissingStub: null,
);
@override
_i2.Future<void> track({
void track({
required String? name,
Map<String, dynamic>? properties = const {},
}) =>
Expand All @@ -94,11 +92,10 @@ class MockTestCustomerIoPlatform extends _i1.Mock
#properties: properties,
},
),
returnValue: _i2.Future<void>.value(),
returnValueForMissingStub: _i2.Future<void>.value(),
returnValueForMissingStub: null,
);
@override
_i2.Future<void> trackMetric({
void trackMetric({
required String? deliveryID,
required String? deviceToken,
required _i5.MetricEvent? event,
Expand All @@ -113,22 +110,20 @@ class MockTestCustomerIoPlatform extends _i1.Mock
#event: event,
},
),
returnValue: _i2.Future<void>.value(),
returnValueForMissingStub: _i2.Future<void>.value(),
returnValueForMissingStub: null,
);
@override
_i2.Future<void> registerDeviceToken({required String? deviceToken}) =>
void registerDeviceToken({required String? deviceToken}) =>
super.noSuchMethod(
Invocation.method(
#registerDeviceToken,
[],
{#deviceToken: deviceToken},
),
returnValue: _i2.Future<void>.value(),
returnValueForMissingStub: _i2.Future<void>.value(),
returnValueForMissingStub: null,
);
@override
_i2.Future<void> screen({
void screen({
required String? title,
Map<String, dynamic>? properties = const {},
}) =>
Expand All @@ -141,35 +136,30 @@ class MockTestCustomerIoPlatform extends _i1.Mock
#properties: properties,
},
),
returnValue: _i2.Future<void>.value(),
returnValueForMissingStub: _i2.Future<void>.value(),
returnValueForMissingStub: null,
);
@override
_i2.Future<void> setDeviceAttributes(
{required Map<String, dynamic>? attributes}) =>
void setDeviceAttributes({required Map<String, dynamic>? attributes}) =>
super.noSuchMethod(
Invocation.method(
#setDeviceAttributes,
[],
{#attributes: attributes},
),
returnValue: _i2.Future<void>.value(),
returnValueForMissingStub: _i2.Future<void>.value(),
returnValueForMissingStub: null,
);
@override
_i2.Future<void> setProfileAttributes(
{required Map<String, dynamic>? attributes}) =>
void setProfileAttributes({required Map<String, dynamic>? attributes}) =>
super.noSuchMethod(
Invocation.method(
#setProfileAttributes,
[],
{#attributes: attributes},
),
returnValue: _i2.Future<void>.value(),
returnValueForMissingStub: _i2.Future<void>.value(),
returnValueForMissingStub: null,
);
_i2.StreamSubscription<dynamic> subscribeToInAppEventListener(
void Function(_i6.InAppEvent)? onEvent) =>
void Function(_i6.InAppEvent)? onEvent) =>
(super.noSuchMethod(
Invocation.method(
#subscribeToInAppEventListener,
Expand Down

0 comments on commit ead4383

Please sign in to comment.