Skip to content

ComparableField String sorting overrides correct backend order with case-sensitive codepoint comparison #2601

@orlikraf

Description

@orlikraf

Which packages are you using?

stream_chat_flutter

On what platforms did you experience the issue?

Web

What version are you using?

stream_chat: ^9.23.0
stream_chat_flutter: ^9.23.0
stream_chat_flutter_core: ^9.23.0

What happened?

The backend API returns users in the correct sort order. However, StreamUserListController re-sorts results client-side using ComparableField.compareTo, which uses String.compareTo — a codepoint-based comparison. This overrides the correct server-side ordering with an incorrect one:

  1. Case-sensitive — lowercase names sort after all uppercase names (e.g., jhon appears after Zara)
  2. Not locale-aware — characters like Ł, Ø, Æ sort after all ASCII letters (e.g., Łukasz appears after Zara instead of after Lukas)

The server presumably handles locale-aware collation correctly, but the client discards that ordering by re-sorting with a naive codepoint comparison.

The issue is in stream_chat/lib/src/core/models/comparable_field.dart, line 27:
(final String a, final String b) => a.compareTo(b),

If client-side re-sorting is necessary (e.g., for merging paginated results), it should at minimum be case-insensitive, and ideally normalize diacritics to match the backend's collation.

Steps to reproduce

1. Create a StreamUserListController with sort: [SortOption.asc('name')]                                                                                                                                               
2. Have users with names starting with lowercase letters or non-ASCII characters (Polish Ł, Norwegian Ø, etc.)                                                                                                           
3. Observe that these users are pushed to the end of the list, despite the backend returning them in the correct alphabetical position

Flutter doctor output

[✓] Flutter (Channel stable, 3.38.7, on Ubuntu 24.04.4 LTS 6.8.0-107-generic, locale en_US.UTF-8) [33ms]
    • Flutter version 3.38.7 on channel stable at /home/rafcio/fvm/versions/3.38.7
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 3b62efc2a3 (3 months ago), 2026-01-13 13:47:42 -0800
    • Engine revision 78fc3012e4
    • Dart version 3.10.7
    • DevTools version 2.51.1
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, omit-legacy-version-file, enable-lldb-debugging

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions