Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/src/surveys/models/survey_appearance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ class SurveyAppearance {
/// Uses the HSP (Highly Sensitive Perceived) color model for perceived brightness.
/// This matches the algorithm used in posthog-js.
static Color _getContrastingTextColor(Color color) {
final r = color.red;
final g = color.green;
final b = color.blue;
final r = color.r;
final g = color.g;
final b = color.b;
Comment on lines +116 to +118
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to confirm

flutter: '>=3.22.0'

color.r | g | b exist alreaduy in flutter 3.22 right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! I tested it with version 3.22.0 (FVM) and works fine.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deprecation message says https://api.flutter.dev/flutter/dart-ui/Color/green.html

Use (*.g * 255.0).round().clamp(0, 255)

Which to me seems that Color.g is in a different range (0-1) than Color.green (0 - 255)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah at least the deprecated message says to do the calculation/round and clamp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could update this to be the exact color that had before but with new API

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah has to be the same color otherwise this function will not function properly

// HSP equation for perceived brightness
final hsp = sqrt(0.299 * (r * r) + 0.587 * (g * g) + 0.114 * (b * b));
// Using 127.5 as threshold (same as JS)
Expand Down