Fix TypeError when an Android inbox message carries a notification payload - #9
Open
fa0311 wants to merge 1 commit into
Open
Conversation
…, not a string On Android, InboxUtils.NotificationMessage.toJson() serialized the push payload with mapToJson(), which returns JSONObject(map).toString() - a JSON-encoded String. After jsonDecode on the Dart side, json['payload'] was therefore a String, and NotificationMessage.fromJson's Map<String, String>.from(json['payload']) threw _TypeError: type 'String' is not a subtype of type 'Map<dynamic, dynamic>'. Because _parseMessages and the onInboxMessagesChanged handler parse every message inside a single map(), one inbox message carrying a notificationMessage with a non-null payload (typical for combined Alert+Inbox pushes) made getMessages, getReadMessages, getUnreadMessages and getDeletedMessages reject and silently dropped inbox-change updates, rendering the whole inbox unusable. iOS is unaffected since its InboxUtility does not emit notificationMessage. Fix: - InboxUtils.kt now puts the payload as a JSONObject so the decoded structure reaching Dart is a Map, matching the declared Dart model. The now-unused mapToJson helper is removed. - NotificationMessage.fromJson is tolerant of both wire shapes: it accepts payload as a Map or as a JSON-encoded String (decoded via jsonDecode), for robustness against older native layers. - Tests cover both wire shapes: unit tests for NotificationMessage.fromJson and an end-to-end getMessages test through the method channel. Also removes a stray debugPrint(json.toString()) from NotificationMessage.fromJson (and the then-unused foundation import), which dumped the full notification payload to the log on every parse.
nakasyou
approved these changes
Jul 19, 2026
nakasyou
approved these changes
Jul 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Android,
InboxUtilsserializesnotificationMessage.payloadwithJSONObject(map).toString(), so Dart receives a JSON string whereNotificationMessage.fromJsonexpects a map and throwstype 'String' is not a subtype of type 'Map<dynamic, dynamic>'. A single alert+inbox push in the inbox is enough to breakgetMessages()and the other getters entirely. iOS is unaffected (it doesn't emitnotificationMessage).The payload is now put as a
JSONObject, and the Dart side accepts both shapes so apps aren't stuck if the native and Dart versions are briefly out of sync. Also removed a leftoverdebugPrintthat dumped the full notification payload on every parse.