Skip to content

fix: alarm comment crash and wrong display format#236

Merged
deaflynx merged 2 commits intothingsboard:masterfrom
deaflynx:fix/alarm-comment
Apr 27, 2026
Merged

fix: alarm comment crash and wrong display format#236
deaflynx merged 2 commits intothingsboard:masterfrom
deaflynx:fix/alarm-comment

Conversation

@deaflynx
Copy link
Copy Markdown
Contributor

@deaflynx deaflynx commented Apr 15, 2026

Summary

Fixes a crash when viewing alarm comments and a display issue where system activity entries (assignments, status changes) were rendered as raw JSON {text: ..., subtype: ..., userName: ...} instead of the actual message.

Root cause

The ThingsBoard API expects the alarm comment payload as a JSON object ({"text": "..."}), but the mobile app was posting comments as plain String values. The server tolerates both formats on write, but returns whatever was stored:

  • System-generated and web-posted comments → returned as Map
  • Mobile-posted comments (legacy) → returned as String

AlarmComment.comment is typed as dynamic in the client library, so widgets calling .edited / accessing the full text assumed a typed object and crashed with NoSuchMethodError: Class 'String' has no instance getter 'edited' whenever they encountered a legacy mobile comment. System activity widgets called toString() on the map, producing the raw {text: ..., subtype: ...} output.

Changes

Flutter app (flutter_thingsboard_app)

  • alarm_details_datasource.dart — post/update now send the API-expected {'text': comment} payload instead of a raw string. Removed _parseComment workaround since parsing is now handled in the client library.
  • Activity widgets (user_comment_widget.dart, system_activity_widget.dart, alarm_edit_comment_textfield.dart) — use (comment as AlarmCommentJsonNode).text / .edited instead of dynamic access.

Dart client library (thingsboard_client)

Note: This PR depends on thingsboard/dart_thingsboard_client#61. Once that client library change is published, the datasource in this PR is a clean pass-through.

Test plan

  • Post a new comment on an alarm — renders correctly, no crash
  • Edit an existing comment — edit dialog pre-populates with the text, "edited" label appears after save
  • View an alarm that has a legacy mobile-posted comment (stored as raw string) — renders correctly, no crash
  • View an alarm with system activity (assignment/unassignment, status change) — shows the human-readable message, not the raw JSON

The API expects comment as a JSON object {text: ...} but the mobile app
was sending raw strings, causing NoSuchMethodError on .edited/.text
access. Normalize comment field in datasource for both Map and legacy
String formats.
Comment parsing (Map/String → AlarmCommentJsonNode) is now handled in
thingsboard_client's AlarmComment.fromJson, so the datasource becomes a
clean pass-through again.
@deaflynx deaflynx added the bug Something isn't working label Apr 22, 2026
@deaflynx deaflynx added this to the 1.8.1 milestone Apr 22, 2026
@deaflynx deaflynx merged commit 188e5b3 into thingsboard:master Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants