fix: compare BleCharacteristic values consistently - #275
Closed
xianjianlf2 wants to merge 4 commits into
Closed
Conversation
BleCharacteristic.operator== compared the `properties` list with `!=`, which is List identity comparison, and hashCode used `properties.hashCode` (also identity based). As a result two characteristics with equal content but distinct list instances were never equal and produced different hash codes, breaking the equality contract and Set/Map lookups. Use `listEquals` for comparison and `Object.hashAll` for hashing, matching the pattern already used in ManufacturerData.
Co-authored-by: Cursor <cursoragent@cursor.com>
xianjianlf2
marked this pull request as ready for review
August 1, 2026 07:44
Contributor
Author
|
已核对当前 main:rebase 后该分支与 upstream/main 完全一致,没有剩余 diff。BleCharacteristic 的值比较修复已由主线提交 |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes BleCharacteristic value semantics so that characteristics built from equivalent data (but different list instances) compare equal and produce stable hashCodes, enabling correct use in Set/Map keys.
Changes:
- Update
BleCharacteristic.==to comparepropertiesby list content rather than list identity. - Update
BleCharacteristic.hashCodeto hashpropertiesby content. - Add a Flutter test covering equality/hashCode behavior and document the change in the changelog.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/ble_characteristic_equality_test.dart | Adds regression tests for value-based equality/hashCode and keying in Set/Map. |
| lib/src/models/ble_service.dart | Implements list-content equality for properties and updates hashCode. |
| CHANGELOG.md | Notes the BleCharacteristic equality/hashCode fix in 2.1.1. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
|
@xianjianlf2 this was addressed already in #267. Am I missing something? |
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.
Summary
Compare
BleCharacteristicvalues by their service UUID, characteristic UUID, and device ID instead of relying on list identity. This makes equality andhashCodestable for equivalent characteristics built from separate list instances.Validation
dartorflutterinstalled. The branch includestest/ble_characteristic_equality_test.dartfor CI coverage.