Skip to content

Commit 47b30aa

Browse files
author
Franco Bugnano
committed
Changed the playSound property to be more compatible with the React Native SDK
1 parent 8d1ecf0 commit 47b30aa

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lib/src/notification.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ class AndroidChannel {
6565
final String? channelDescription;
6666
final bool? lights;
6767
final Color? lightColor;
68-
final bool? bypassDnd; // ?
69-
final String? playSound;
68+
final String playSound;
7069
final AndroidImportance? importance;
7170
final AndroidVisibility? visibility;
7271
final bool? vibrate;
@@ -79,8 +78,7 @@ class AndroidChannel {
7978
this.channelDescription,
8079
this.lights,
8180
this.lightColor,
82-
this.bypassDnd,
83-
this.playSound,
81+
this.playSound = 'default',
8482
this.importance,
8583
this.visibility,
8684
this.vibrate,
@@ -92,12 +90,10 @@ class IOSPermissions {
9290
final bool alert;
9391
final bool badge;
9492
final bool sound;
95-
final bool? critical; // ?
9693
const IOSPermissions({
9794
this.alert = true,
9895
this.badge = true,
9996
this.sound = true,
100-
this.critical,
10197
});
10298
}
10399

@@ -245,8 +241,12 @@ Future<void> _onReceiveMessageFromPort(RemoteMessage firebaseMessage) async {
245241
styleInformation = DefaultStyleInformation(false, false);
246242
}
247243

244+
// We default to not playing sounds, unless a non-empty string is provided
245+
final playSound = _androidChannel!.playSound.isNotEmpty;
248246
RawResourceAndroidNotificationSound? sound;
249-
if ((_androidChannel!.playSound is String) && _androidChannel!.playSound!.isNotEmpty) {
247+
248+
// We use the string 'default' for the default sound (for compatibility with the React Natve SDK)
249+
if (playSound && (_androidChannel!.playSound != 'default')) {
250250
sound = RawResourceAndroidNotificationSound(_androidChannel!.playSound);
251251
}
252252

@@ -256,6 +256,7 @@ Future<void> _onReceiveMessageFromPort(RemoteMessage firebaseMessage) async {
256256
_androidChannel!.channelName,
257257
channelDescription: _androidChannel!.channelDescription,
258258
importance: _androidChannel!.importance?.toLocalNotification() ?? Importance.high,
259+
playSound: playSound,
259260
sound: sound,
260261
enableVibration: _androidChannel!.vibrate ?? true,
261262
vibrationPattern: _androidChannel!.vibrationPattern,

0 commit comments

Comments
 (0)