Skip to content

Fix Flutter realtime message list parsing#1547

Open
mackings wants to merge 1 commit into
appwrite:masterfrom
mackings:fix-flutter-realtime-message-map-fields
Open

Fix Flutter realtime message list parsing#1547
mackings wants to merge 1 commit into
appwrite:masterfrom
mackings:fix-flutter-realtime-message-map-fields

Conversation

@mackings
Copy link
Copy Markdown

@mackings mackings commented May 19, 2026

Fixes appwrite/sdk-for-flutter#302

Updates the generated Flutter RealtimeMessage.fromMap implementation to safely parse events and channels when realtime payloads provide those fields as maps instead of lists.

The parser now supports:

  • list values
  • map values like { "0": "event" }.
  • map keys like { "event": true }

Validation:

  • docker run --rm -v "$(pwd)":/app -w /app php:8.3-cli php example.php flutter
  • flutter test test/src/realtime_message_test.dart
  • flutter analyze lib/src/realtime_message.dart test/src/realtime_message_test.dart
  • uvx djlint templates/ --lint

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 19, 2026

Greptile Summary

This PR fixes Flutter realtime message parsing to handle server payloads where events and channels arrive as maps (either array-indexed or key-as-value) rather than plain lists, and adds a comprehensive test suite for the new logic.

  • Replaces the direct List<String>.from(map['events'] ?? []) cast with a new _stringListFrom helper that handles null, Iterable, numeric-key maps (uses values), and non-numeric-key maps (uses keys), matching the three documented server formats.
  • Adds a new realtime_message_test.dart.twig template with tests for all supported input shapes — including null/absent fields, mixed-value maps, round-trip JSON, and a TypeError assertion for non-string list elements — and registers it in Flutter.php.

Confidence Score: 5/5

The change is safe to merge; it narrows an existing runtime crash into a handled code path and the new test suite covers all documented server formats including edge cases.

The logic in _stringListFrom correctly handles all documented server formats. The only noteworthy point is a minor inconsistency in _isArrayIndexKey where negative integer strings pass the guard while negative int values do not, but this edge case does not arise with real JSON payloads.

No files require special attention.

Important Files Changed

Filename Overview
src/SDK/Language/Flutter.php Registers the new realtime_message_test.dart.twig template for generation, placed alongside the other realtime test entries.
templates/flutter/lib/src/realtime_message.dart.twig Replaces the brittle List.from cast with _stringListFrom, which safely handles null, Iterable, and two Map formats (array-indexed keys vs. non-index keys). Minor inconsistency in _isArrayIndexKey between int and String negative-index handling.
templates/flutter/test/src/realtime_message_test.dart.twig New test template covering all documented parsing paths: list input, string-indexed map, int-indexed map, non-index key map, mixed-value map, null/absent fields, non-string list items (TypeError), and round-trip JSON serialisation.

Reviews (2): Last reviewed commit: "Fix Flutter realtime message list parsin..." | Re-trigger Greptile

Comment thread templates/flutter/lib/src/realtime_message.dart.twig Outdated
Comment thread templates/flutter/lib/src/realtime_message.dart.twig
Comment thread templates/flutter/test/src/realtime_message_test.dart.twig
@mackings mackings force-pushed the fix-flutter-realtime-message-map-fields branch from fa8ae02 to e5ad7ee Compare May 19, 2026 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Bug Report: realtimeMessage.fromMap crashes with _Map<String, dynamic> is not a subtype of Iterable<dynamic>

1 participant