Repository navigation
data_detector: fix TypeError in TextCheckingResult.date and duration - #527
Merged
Merged
Conversation
Both getters cast a double (NSTimeInterval * 1e6) to int with `as int`. This cast always fails, so every call threw a TypeError. Round the value to int instead. The tests now skip with Platform.isMacOS. defaultTargetPlatform is android under flutter test, so the old skip condition skipped them on all hosts.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The narrow fix addresses both invalid casts with regression coverage; macOS tests were not independently rerun.
No open issues 🎉
What changed in this PR
Fixes invalid numeric casts in data_detector’s date and duration getters.
Changes:
- Rounds microsecond values to integers instead of casting.
- Enables tests on macOS using
Platform.isMacOS. - Adds regression coverage for both getters.
| File | Description |
|---|---|
| packages/data_detector/test/data_detector_test.dart | Corrects platform checks and adds a date regression test. |
| packages/data_detector/lib/data_detector.dart | Replaces failing casts with .round(). |
Review effort: Balanced
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
TextCheckingResult.dateandTextCheckingResult.durationcast adouble(NSTimeInterval * 1e6) tointwithas int. This cast always fails in Dart, so each call threw aTypeError.The tests now skip with
!Platform.isMacOS. Underflutter test,defaultTargetPlatformisandroidon all hosts, so the old condition skipped the tests everywhere.Evidence
New test
date: detectNSTextCheckingTypeDatein"on 2024-01-02 10:00", then readdateandduration. Run withflutter teston macOS.type 'double' is not a subtype of type 'int' in type castAfter:
+2: All tests passed!(the existing link test now runs too)Merge Danger
Door: two-way
Blast Radius: small
Only the two getters change. Before, they always threw, so no caller can depend on the old result.