Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ios/onesignal_flutter/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func oneSignalEnvFlag(_ name: String) -> Bool {
let oneSignalDisableLocation = oneSignalEnvFlag("ONESIGNAL_DISABLE_LOCATION")

var oneSignalDependencies: [Target.Dependency] = [
.product(name: "FlutterFramework", package: "FlutterFramework"),
.product(name: "OneSignalFramework", package: "OneSignal-XCFramework"),
.product(name: "OneSignalInAppMessages", package: "OneSignal-XCFramework"),
.product(name: "OneSignalExtension", package: "OneSignal-XCFramework"),
Expand All @@ -30,6 +31,7 @@ let package = Package(
.library(name: "onesignal-flutter", targets: ["onesignal_flutter"])
],
dependencies: [
.package(name: "FlutterFramework", path: "../FlutterFramework"),
.package(url: "https://github.com/OneSignal/OneSignal-XCFramework", exact: "5.8.1"),
],
targets: [
Expand Down
24 changes: 15 additions & 9 deletions lib/onesignal_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,24 @@ class OneSignal {
/// user context to that specific user.
static Future<void> login(String externalId) async {
if (isMissing(externalId, 'login: externalId')) return;
return await _channel
.invokeMethod('OneSignal#login', {'externalId': externalId});
return await _channel.invokeMethod('OneSignal#login', {
'externalId': externalId,
});
}

/// Login to OneSignal under the user identified by the [externalId] provided.
///
/// The act of logging a user into the OneSignal SDK will switch the
/// user context to that specific user.
@Deprecated(
'Do not use, this method is not implemented. See https://documentation.onesignal.com/docs/identity-verification for updates.')
'Do not use, this method is not implemented. See https://documentation.onesignal.com/docs/identity-verification for updates.',
)
static Future<void> loginWithJWT(String externalId, String jwt) async {
if (defaultTargetPlatform == TargetPlatform.android) {
return await _channel.invokeMethod(
'OneSignal#loginWithJWT', {'externalId': externalId, 'jwt': jwt});
return await _channel.invokeMethod('OneSignal#loginWithJWT', {
'externalId': externalId,
'jwt': jwt,
});
}
}

Expand All @@ -96,15 +100,17 @@ class OneSignal {
/// This field is only relevant when the application has
/// opted into data privacy protections. See [consentRequired].
static Future<void> consentGiven(bool granted) async {
return await _channel
.invokeMethod("OneSignal#consentGiven", {'granted': granted});
return await _channel.invokeMethod("OneSignal#consentGiven", {
'granted': granted,
});
}

/// Allows you to completely disable the SDK until your app calls the
/// OneSignal.consentGiven(true) function. This is useful if you want
/// to show a Terms and Conditions or privacy popup for GDPR.
static Future<void> consentRequired(bool require) async {
return await _channel
.invokeMethod("OneSignal#consentRequired", {'required': require});
return await _channel.invokeMethod("OneSignal#consentRequired", {
'required': require,
});
}
}
10 changes: 6 additions & 4 deletions lib/src/debug.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ class OneSignalDebug {
/// The parameter [logLevel] controls
/// how verbose logs in the console/logcat are
Future<void> setLogLevel(OSLogLevel logLevel) async {
return await _channel
.invokeMethod("OneSignal#setLogLevel", {'logLevel': logLevel.index});
return await _channel.invokeMethod("OneSignal#setLogLevel", {
'logLevel': logLevel.index,
});
}

/// Sets the log level for the SDK.
///
/// The parameter [visualLevel] controls
/// if the SDK will show alerts for each logged message
Future<void> setAlertLevel(OSLogLevel visualLevel) async {
return await _channel.invokeMethod(
"OneSignal#setAlertLevel", {'visualLevel': visualLevel.index});
return await _channel.invokeMethod("OneSignal#setAlertLevel", {
'visualLevel': visualLevel.index,
});
}
}
2 changes: 1 addition & 1 deletion lib/src/defines.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ enum OSiOSSettings {
inAppAlerts,
inAppLaunchUrl,
promptBeforeOpeningPushUrl,
inFocusDisplayOption
inFocusDisplayOption,
}

enum OSSession { DIRECT, INDIRECT, UNATTRIBUTED, DISABLED }
Expand Down
13 changes: 7 additions & 6 deletions lib/src/inappmessage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ class OSInAppMessageClickEvent extends JSONStringRepresentable {

OSInAppMessageClickEvent(Map<String, dynamic> json) {
this.message = OSInAppMessage(json["message"].cast<String, dynamic>());
this.result =
OSInAppMessageClickResult(json["result"].cast<String, dynamic>());
this.result = OSInAppMessageClickResult(
json["result"].cast<String, dynamic>(),
);
}

String jsonRepresentation() {
Expand Down Expand Up @@ -42,10 +43,10 @@ class OSInAppMessageClickResult extends JSONStringRepresentable {
}

Map<String, dynamic> mapRepresentation() => {
'action_id': this.actionId,
'url': this.url,
'closing_message': this.closingMessage,
};
'action_id': this.actionId,
'url': this.url,
'closing_message': this.closingMessage,
};

String jsonRepresentation() => convertToJsonString(mapRepresentation());
}
Expand Down
39 changes: 26 additions & 13 deletions lib/src/inappmessages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ import 'package:onesignal_flutter/src/utils.dart';
typedef void OnClickInAppMessageListener(OSInAppMessageClickEvent event);

typedef void OnWillDisplayInAppMessageListener(
OSInAppMessageWillDisplayEvent event);
OSInAppMessageWillDisplayEvent event,
);
typedef void OnDidDisplayInAppMessageListener(
OSInAppMessageDidDisplayEvent event);
OSInAppMessageDidDisplayEvent event,
);
typedef void OnWillDismissInAppMessageListener(
OSInAppMessageWillDismissEvent event);
OSInAppMessageWillDismissEvent event,
);
typedef void OnDidDismissInAppMessageListener(
OSInAppMessageDidDismissEvent event);
OSInAppMessageDidDismissEvent event,
);

class OneSignalInAppMessages {
// private channels used to bridge to ObjC/Java
Expand Down Expand Up @@ -86,27 +90,36 @@ class OneSignalInAppMessages {
if (call.method == 'OneSignal#onClickInAppMessage') {
for (var listener in _clickListeners) {
listener(
OSInAppMessageClickEvent(call.arguments.cast<String, dynamic>()));
OSInAppMessageClickEvent(call.arguments.cast<String, dynamic>()),
);
}
} else if (call.method == 'OneSignal#onWillDisplayInAppMessage') {
for (var listener in _willDisplayListeners) {
listener(OSInAppMessageWillDisplayEvent(
call.arguments.cast<String, dynamic>()));
listener(
OSInAppMessageWillDisplayEvent(
call.arguments.cast<String, dynamic>(),
),
);
}
} else if (call.method == 'OneSignal#onDidDisplayInAppMessage') {
for (var listener in _didDisplayListeners) {
listener(OSInAppMessageDidDisplayEvent(
call.arguments.cast<String, dynamic>()));
listener(
OSInAppMessageDidDisplayEvent(call.arguments.cast<String, dynamic>()),
);
}
} else if (call.method == 'OneSignal#onWillDismissInAppMessage') {
for (var listener in _willDismissListeners) {
listener(OSInAppMessageWillDismissEvent(
call.arguments.cast<String, dynamic>()));
listener(
OSInAppMessageWillDismissEvent(
call.arguments.cast<String, dynamic>(),
),
);
}
} else if (call.method == 'OneSignal#onDidDismissInAppMessage') {
for (var listener in _didDismissListeners) {
listener(OSInAppMessageDidDismissEvent(
call.arguments.cast<String, dynamic>()));
listener(
OSInAppMessageDidDismissEvent(call.arguments.cast<String, dynamic>()),
);
}
}
return null;
Expand Down
40 changes: 26 additions & 14 deletions lib/src/liveactivities.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ class OneSignalLiveActivities {
return;
}
if (defaultTargetPlatform == TargetPlatform.iOS) {
return await _channel.invokeMethod("OneSignal#enterLiveActivity",
{'activityId': activityId, 'token': token});
return await _channel.invokeMethod("OneSignal#enterLiveActivity", {
'activityId': activityId,
'token': token,
});
}
}

Expand All @@ -28,8 +30,9 @@ class OneSignalLiveActivities {
Future<void> exitLiveActivity(String activityId) async {
if (isMissing(activityId, 'exitLiveActivity: activityId')) return;
if (defaultTargetPlatform == TargetPlatform.iOS) {
return await _channel.invokeMethod(
"OneSignal#exitLiveActivity", {'activityId': activityId});
return await _channel.invokeMethod("OneSignal#exitLiveActivity", {
'activityId': activityId,
});
}
}

Expand All @@ -55,8 +58,9 @@ class OneSignalLiveActivities {
};
}

return await _channel
.invokeMethod("OneSignal#setupDefault", {'options': optionsMap});
return await _channel.invokeMethod("OneSignal#setupDefault", {
'options': optionsMap,
});
}
}

Expand All @@ -67,7 +71,10 @@ class OneSignalLiveActivities {
///
/// Only applies to iOS.
Future<void> startDefault(
String activityId, dynamic attributes, dynamic content) async {
String activityId,
dynamic attributes,
dynamic content,
) async {
if (isMissing(activityId, 'startDefault: activityId') ||
!_isMap(attributes, 'startDefault: attributes') ||
!_isMap(content, 'startDefault: content')) {
Expand All @@ -77,7 +84,7 @@ class OneSignalLiveActivities {
return await _channel.invokeMethod("OneSignal#startDefault", {
'activityId': activityId,
'attributes': attributes,
'content': content
'content': content,
});
}
}
Expand All @@ -94,8 +101,10 @@ class OneSignalLiveActivities {
return;
}
if (defaultTargetPlatform == TargetPlatform.iOS) {
return await _channel.invokeMethod("OneSignal#setPushToStartToken",
{'activityType': activityType, 'token': token});
return await _channel.invokeMethod("OneSignal#setPushToStartToken", {
'activityType': activityType,
'token': token,
});
}
}

Expand All @@ -109,8 +118,9 @@ class OneSignalLiveActivities {
return;
}
if (defaultTargetPlatform == TargetPlatform.iOS) {
return await _channel.invokeMethod(
"OneSignal#removePushToStartToken", {'activityType': activityType});
return await _channel.invokeMethod("OneSignal#removePushToStartToken", {
'activityType': activityType,
});
}
}

Expand All @@ -129,6 +139,8 @@ class LiveActivitySetupOptions {
/// When true, OneSignal will listen for pushToUpdate tokens for each started live activity.
final bool enablePushToUpdate;

LiveActivitySetupOptions(
{this.enablePushToStart = true, this.enablePushToUpdate = true});
LiveActivitySetupOptions({
this.enablePushToStart = true,
this.enablePushToUpdate = true,
});
}
36 changes: 21 additions & 15 deletions lib/src/notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,19 @@ class OSNotification extends JSONStringRepresentable {
this.androidNotificationId = json['androidNotificationId'] as int?;
if (json.containsKey('backgroundImageLayout')) {
this.backgroundImageLayout = OSAndroidBackgroundImageLayout(
json['backgroundImageLayout'].cast<String, dynamic>());
json['backgroundImageLayout'].cast<String, dynamic>(),
);
}
if (json.containsKey('groupedNotifications')) {
final dynamic jsonGroupedNotifications = json['groupedNotifications'];
final List<dynamic> jsonList = jsonGroupedNotifications is String
? jsonDecode(jsonGroupedNotifications) as List<dynamic>
: jsonGroupedNotifications as List<dynamic>;
this.groupedNotifications = jsonList
.map((dynamic item) =>
OSNotification((item as Map).cast<String, dynamic>()))
.map(
(dynamic item) =>
OSNotification((item as Map).cast<String, dynamic>()),
)
.toList();
}

Expand Down Expand Up @@ -277,8 +280,9 @@ class OSNotification extends JSONStringRepresentable {
if (this.launchUrl != null) 'launchUrl': this.launchUrl,
if (this.additionalData != null) 'additionalData': this.additionalData,
if (this.buttons != null)
'buttons':
this.buttons!.map((button) => button.mapRepresentation()).toList(),
'buttons': this.buttons!
.map((button) => button.mapRepresentation())
.toList(),
if (this.rawPayload != null) 'rawPayload': this.rawPayload,
if (this.attachments != null) 'attachments': this.attachments,
if (this.contentAvailable != null)
Expand All @@ -292,8 +296,7 @@ class OSNotification extends JSONStringRepresentable {
if (this.interruptionLevel != null)
'interruptionLevel': this.interruptionLevel,
if (this.groupedNotifications != null)
'groupedNotifications': this
.groupedNotifications!
'groupedNotifications': this.groupedNotifications!
.map((notification) => notification.mapRepresentation())
.toList(),
if (this.androidNotificationId != null)
Expand All @@ -313,8 +316,8 @@ class OSNotification extends JSONStringRepresentable {
if (this.collapseId != null) 'collapseId': this.collapseId,
if (this.priority != null) 'priority': this.priority,
if (this.backgroundImageLayout != null)
'backgroundImageLayout':
this.backgroundImageLayout!.mapRepresentation(),
'backgroundImageLayout': this.backgroundImageLayout!
.mapRepresentation(),
};
}

Expand All @@ -334,8 +337,10 @@ class OSNotificationClickResult extends JSONStringRepresentable {
this.url = json['url'];
}

Map<String, dynamic> mapRepresentation() =>
{'action_id': this.actionId, 'url': this.url};
Map<String, dynamic> mapRepresentation() => {
'action_id': this.actionId,
'url': this.url,
};

String jsonRepresentation() => convertToJsonString(mapRepresentation());
}
Expand Down Expand Up @@ -423,7 +428,7 @@ class OSAndroidBackgroundImageLayout extends JSONStringRepresentable {
return {
'image': this.image,
'titleTextColor': this.titleTextColor,
'bodyTextColor': this.bodyTextColor
'bodyTextColor': this.bodyTextColor,
};
}

Expand All @@ -448,8 +453,9 @@ class OSNotificationWillDisplayEvent extends JSONStringRepresentable {
}

String jsonRepresentation() {
return convertToJsonString(
{'notification': this.notification.mapRepresentation()});
return convertToJsonString({
'notification': this.notification.mapRepresentation(),
});
}
}

Expand All @@ -469,7 +475,7 @@ class OSNotificationClickEvent extends JSONStringRepresentable {
String jsonRepresentation() {
return convertToJsonString({
'notification': this.notification.mapRepresentation(),
'result': this.result.mapRepresentation()
'result': this.result.mapRepresentation(),
});
}
}
Loading
Loading