Skip to content

Commit

Permalink
chore: refactor dart call forwarding
Browse files Browse the repository at this point in the history
  • Loading branch information
mrehan27 committed Nov 26, 2024
1 parent 84a5fa7 commit 7e4fd34
Show file tree
Hide file tree
Showing 16 changed files with 257 additions and 270 deletions.
4 changes: 2 additions & 2 deletions apps/amiapp_flutter/lib/src/screens/dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class _DashboardScreenState extends State<DashboardScreen> {
.getBuildInfo()
.then((value) => setState(() => _buildInfo = value));

inAppMessageStreamSubscription =
CustomerIO.instance.inAppMessaging.subscribeToInAppEventListener(handleInAppEvent);
inAppMessageStreamSubscription = CustomerIO.inAppMessaging
.subscribeToInAppEventListener(handleInAppEvent);

// Setup 3rd party SDK, flutter-fire.
// We install this SDK into sample app to make sure the CIO SDK behaves as expected when there is another SDK installed that handles push notifications.
Expand Down
33 changes: 15 additions & 18 deletions lib/customer_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:flutter/cupertino.dart';

import 'customer_io_config.dart';
import 'customer_io_enums.dart';
import 'customer_io_platform_interface.dart';
import 'data_pipelines/customer_io_platform_interface.dart';
import 'extensions/map_extensions.dart';
import 'messaging_in_app/platform_interface.dart';
import 'messaging_push/platform_interface.dart';
Expand Down Expand Up @@ -61,17 +61,13 @@ class CustomerIO {

/// Access push messaging functionality
static CustomerIOMessagingPushPlatform get pushMessaging {
if (_instance == null) {
throw StateError(
'CustomerIO SDK must be initialized before accessing push module.\n'
'Call CustomerIO.initialize() first.',
);
}
return _instance!._pushMessaging;
return instance._pushMessaging;
}

/// Access in-app messaging functionality
CustomerIOMessagingInAppPlatform get inAppMessaging => _inAppMessaging;
static CustomerIOMessagingInAppPlatform get inAppMessaging {
return instance._inAppMessaging;
}

/// To initialize the plugin
///
Expand All @@ -95,7 +91,7 @@ class CustomerIO {
///
/// @param userId unique identifier for a profile
/// @param traits (Optional) params to set profile attributes
void identify(
Future<void> identify(
{required String userId, Map<String, dynamic> traits = const {}}) {
return _platform.identify(
userId: userId, traits: traits.excludeNullValues());
Expand All @@ -105,23 +101,23 @@ class CustomerIO {
///
/// If a profile exists, clearIdentify will stop identifying the profile.
/// If no profile exists, request to clearIdentify will be ignored.
void clearIdentify() {
_platform.clearIdentify();
Future<void> clearIdentify() {
return _platform.clearIdentify();
}

/// To track user events like loggedIn, addedItemToCart etc.
/// You may also track events with additional yet optional data.
///
/// @param name event name to be tracked
/// @param properties (Optional) params to be sent with event
void track(
Future<void> track(
{required String name, Map<String, dynamic> properties = const {}}) {
return _platform.track(
name: name, properties: properties.excludeNullValues());
}

/// Track a push metric
void trackMetric(
Future<void> trackMetric(
{required String deliveryID,
required String deviceToken,
required MetricEvent event}) {
Expand All @@ -131,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
void registerDeviceToken({required String deviceToken}) {
Future<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
void screen(
Future<void> screen(
{required String title, Map<String, dynamic> properties = const {}}) {
return _platform.screen(
title: title, properties: properties.excludeNullValues());
Expand All @@ -149,15 +145,16 @@ class CustomerIO {
/// such as app preferences, timezone etc
///
/// @param attributes device attributes
void setDeviceAttributes({required Map<String, dynamic> attributes}) {
Future<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
void setProfileAttributes({required Map<String, dynamic> attributes}) {
Future<void> setProfileAttributes(
{required Map<String, dynamic> attributes}) {
return _platform.setProfileAttributes(
attributes: attributes.excludeNullValues());
}
Expand Down
152 changes: 0 additions & 152 deletions lib/customer_io_method_channel.dart

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
// TODO: Cleanup this file later when all commented methods are implemented

class MethodConsts {
static const String initialize = "initialize";
static const String identify = "identify";
/// Methods specific to Data Pipelines module.
class NativeMethods {
static const String clearIdentify = "clearIdentify";
static const String track = "track";
static const String trackMetric = "trackMetric";
static const String identify = "identify";
static const String initialize = "initialize";
static const String screen = "screen";
static const String setDeviceAttributes = "setDeviceAttributes";
static const String setProfileAttributes = "setProfileAttributes";
static const String registerDeviceToken = "registerDeviceToken";
static const String onMessageReceived = "onMessageReceived";
static const String dismissMessage = "dismissMessage";
static const String getRegisteredDeviceToken = "getRegisteredDeviceToken";
static const String track = "track";
static const String trackMetric = "trackMetric";
}

class TrackingConsts {
static const String userId = "userId";
/// Method parameters specific to DataPipelines module.
class NativeMethodParams {
static const String attributes = "attributes";
static const String traits = "traits";
static const String eventName = "eventName";
static const String token = "token";
static const String deliveryId = "deliveryId";
static const String deliveryToken = "deliveryToken";
static const String metricEvent = "metricEvent";
static const String message = "message";
static const String handleNotificationTrigger = "handleNotificationTrigger";

static const String name = "name";
static const String properties = "properties";
static const String title = "title";
static const String token = "token";
static const String traits = "traits";
static const String userId = "userId";
}
Loading

0 comments on commit 7e4fd34

Please sign in to comment.