Skip to content

Commit

Permalink
[NOT-3042] hotfix: open notification as string (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
igorgsduarte authored Jun 18, 2024
1 parent e609f7b commit ed6e8c8
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 22 deletions.
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:flutter/material.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:provider/provider.dart';


import 'app.dart';
import 'constants.dart';

Expand All @@ -21,6 +20,7 @@ Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
DitoSDK dito = DitoSDK();
dito.initialize(
apiKey: Constants.ditoApiKey, secretKey: Constants.ditoSecretKey);
await dito.initializePushNotificationService();

final notification = DataPayload.fromJson(jsonDecode(message.data["data"]));

Expand Down
10 changes: 10 additions & 0 deletions package/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 0.5.4 (Jun 05, 2024)

### Bug Fixes

- Bug Fixes
- Fixing notification id from dataPayload for string (this enable the new sender)
- Additional Notes
- No additional notes in this version.
-

## 0.5.3 (Jun 04, 2024)

### Bug Fixes
Expand Down
28 changes: 12 additions & 16 deletions package/lib/entity/data_payload.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,29 @@ class Details {
}

class DataPayload {
final int reference;
final int notification;
final int notification_log_id;
final String reference;
final String identifier;
final String notification;
final String notification_log_id;
final Details details;

DataPayload(this.reference, this.notification, this.notification_log_id,
this.details);
DataPayload(this.reference, this.identifier, this.notification,
this.notification_log_id, this.details);

factory DataPayload.fromJson(dynamic json) {
assert(json is Map);

final reference = json["reference"] is int
? json["reference"]
: int.parse(json["reference"]);
final notification = json["notification"] is int
? json["notification"]
: int.parse(json["notification"]);
final notificationLogId = json["notification_log_id"] is int
? json["notification_log_id"]
: int.parse(json["notification_log_id"]);

return DataPayload(reference, notification, notificationLogId,
return DataPayload(
json["reference"],
json["identifier"],
json["notification"],
json["notification_log_id"],
Details.fromJson(json["details"]));
}

Map<String, dynamic> toJson() => {
'reference': reference,
'identifier': identifier,
'notification': notification,
'notification_log_id': notification_log_id,
'details': details.toJson(),
Expand Down
12 changes: 8 additions & 4 deletions package/lib/services/notification_service.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:package_info_plus/package_info_plus.dart';
Expand Down Expand Up @@ -142,10 +143,13 @@ class NotificationService {
selectNotificationStream.stream.listen((String? payload) async {
if (payload != null) {
final data = DataPayload.fromJson(jsonDecode(payload));
await _dito.openNotification(
notificationId: data.notification.toString(),
identifier: data.reference.toString(),
reference: data.reference.toString());

if (data.notification.isNotEmpty) {
await _dito.openNotification(
notificationId: data.notification,
identifier: data.identifier,
reference: data.reference);
}
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion package/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: dito_sdk
description: A Flutter package by Dito that enables user registration and user event tracking.
version: 0.5.3
version: 0.5.4
homepage: https://github.com/ditointernet/sdk_mobile_flutter

environment:
Expand Down

0 comments on commit ed6e8c8

Please sign in to comment.