From 0175935b23413631d5bebf83bae7fcf767fefc96 Mon Sep 17 00:00:00 2001 From: Kyle Swank Date: Thu, 11 Dec 2025 08:47:09 -0500 Subject: [PATCH 1/3] Improve consistency when handling colors in surveys. Co-authored-by: Tate --- lib/src/surveys/models/survey_appearance.dart | 61 ++++++++++++++----- .../surveys/widgets/number_rating_button.dart | 10 +-- .../surveys/widgets/open_text_question.dart | 8 ++- lib/src/surveys/widgets/question_header.dart | 4 +- lib/src/surveys/widgets/rating_icons.dart | 6 +- lib/src/surveys/widgets/rating_question.dart | 9 +-- .../surveys/widgets/survey_bottom_sheet.dart | 5 +- .../surveys/widgets/survey_choice_button.dart | 18 +++--- 8 files changed, 79 insertions(+), 42 deletions(-) diff --git a/lib/src/surveys/models/survey_appearance.dart b/lib/src/surveys/models/survey_appearance.dart index c01ecddc..aa737e41 100644 --- a/lib/src/surveys/models/survey_appearance.dart +++ b/lib/src/surveys/models/survey_appearance.dart @@ -5,54 +5,85 @@ import 'posthog_display_survey_appearance.dart'; @immutable class SurveyAppearance { const SurveyAppearance({ - this.backgroundColor, + this.backgroundColor = Colors.white, this.submitButtonColor = Colors.black, this.submitButtonText = 'Submit', this.submitButtonTextColor = Colors.white, - this.descriptionTextColor, - this.ratingButtonColor, - this.ratingButtonActiveColor, + this.descriptionTextColor = Colors.black, + this.questionTextColor = Colors.black, + this.closeButtonColor = Colors.black, + this.ratingButtonColor = const Color(0xFFEEEEEE), + this.ratingButtonActiveColor = Colors.black, + this.ratingButtonSelectedTextColor = Colors.white, + this.ratingButtonUnselectedTextColor = const Color(0x80000000), this.displayThankYouMessage = true, this.thankYouMessageHeader = 'Thank you for your feedback!', this.thankYouMessageDescription, this.thankYouMessageCloseButtonText = 'Close', - this.borderColor, + this.borderColor = const Color(0xFFBDBDBD), + this.inputBackgroundColor = Colors.white, + this.inputTextColor = Colors.black, + this.inputPlaceholderColor = const Color(0xFF757575), + this.choiceButtonBorderColor = Colors.black, + this.choiceButtonTextColor = Colors.black, }); - final Color? backgroundColor; + final Color backgroundColor; final Color submitButtonColor; final String submitButtonText; final Color submitButtonTextColor; - final Color? descriptionTextColor; - final Color? ratingButtonColor; - final Color? ratingButtonActiveColor; + final Color descriptionTextColor; + final Color questionTextColor; + final Color closeButtonColor; + final Color ratingButtonColor; + final Color ratingButtonActiveColor; + final Color ratingButtonSelectedTextColor; + final Color ratingButtonUnselectedTextColor; final bool displayThankYouMessage; final String thankYouMessageHeader; final String? thankYouMessageDescription; final String thankYouMessageCloseButtonText; - final Color? borderColor; + final Color borderColor; + final Color inputBackgroundColor; + final Color inputTextColor; + final Color inputPlaceholderColor; + final Color choiceButtonBorderColor; + final Color choiceButtonTextColor; /// Creates a [SurveyAppearance] from a [PostHogDisplaySurveyAppearance] static SurveyAppearance fromPostHog( PostHogDisplaySurveyAppearance? appearance) { return SurveyAppearance( - backgroundColor: _colorFromHex(appearance?.backgroundColor), + backgroundColor: + _colorFromHex(appearance?.backgroundColor) ?? Colors.white, submitButtonColor: _colorFromHex(appearance?.submitButtonColor) ?? Colors.black, submitButtonText: appearance?.submitButtonText ?? 'Submit', submitButtonTextColor: _colorFromHex(appearance?.submitButtonTextColor) ?? Colors.white, - descriptionTextColor: _colorFromHex(appearance?.descriptionTextColor), - ratingButtonColor: _colorFromHex(appearance?.ratingButtonColor), + descriptionTextColor: + _colorFromHex(appearance?.descriptionTextColor) ?? Colors.black, + questionTextColor: Colors.black, + closeButtonColor: Colors.black, + ratingButtonColor: _colorFromHex(appearance?.ratingButtonColor) ?? + const Color(0xFFEEEEEE), ratingButtonActiveColor: - _colorFromHex(appearance?.ratingButtonActiveColor), + _colorFromHex(appearance?.ratingButtonActiveColor) ?? Colors.black, + ratingButtonSelectedTextColor: Colors.white, + ratingButtonUnselectedTextColor: const Color(0x80000000), displayThankYouMessage: appearance?.displayThankYouMessage ?? true, thankYouMessageHeader: appearance?.thankYouMessageHeader ?? 'Thank you for your feedback!', thankYouMessageDescription: appearance?.thankYouMessageDescription, thankYouMessageCloseButtonText: appearance?.thankYouMessageCloseButtonText ?? 'Close', - borderColor: _colorFromHex(appearance?.borderColor), + borderColor: + _colorFromHex(appearance?.borderColor) ?? const Color(0xFFBDBDBD), + inputBackgroundColor: Colors.white, + inputTextColor: Colors.black, + inputPlaceholderColor: const Color(0xFF757575), + choiceButtonBorderColor: Colors.black, + choiceButtonTextColor: Colors.black, ); } diff --git a/lib/src/surveys/widgets/number_rating_button.dart b/lib/src/surveys/widgets/number_rating_button.dart index d292ac65..f5127058 100644 --- a/lib/src/surveys/widgets/number_rating_button.dart +++ b/lib/src/surveys/widgets/number_rating_button.dart @@ -22,8 +22,8 @@ class NumberRatingButton extends StatelessWidget { @override Widget build(BuildContext context) { final buttonColor = isSelected - ? appearance.ratingButtonActiveColor ?? Colors.black - : appearance.ratingButtonColor ?? Colors.grey.shade200; + ? appearance.ratingButtonActiveColor + : appearance.ratingButtonColor; return Expanded( child: Row( @@ -61,8 +61,8 @@ class NumberRatingButton extends StatelessWidget { value.toString(), style: TextStyle( color: isSelected - ? Colors.white - : Colors.black.withValues(alpha: 0.5), + ? appearance.ratingButtonSelectedTextColor + : appearance.ratingButtonUnselectedTextColor, fontSize: 16, fontWeight: FontWeight.bold, ), @@ -78,7 +78,7 @@ class NumberRatingButton extends StatelessWidget { Container( height: 45, width: 1, - color: appearance.borderColor ?? Colors.grey.shade400, + color: appearance.borderColor, ), ], ), diff --git a/lib/src/surveys/widgets/open_text_question.dart b/lib/src/surveys/widgets/open_text_question.dart index d00caace..b0fe8e9c 100644 --- a/lib/src/surveys/widgets/open_text_question.dart +++ b/lib/src/surveys/widgets/open_text_question.dart @@ -66,8 +66,8 @@ class _OpenTextQuestionState extends State { minHeight: 80, ), decoration: BoxDecoration( - color: Colors.white, - border: Border.all(color: Colors.grey.shade400), + color: widget.appearance.inputBackgroundColor, + border: Border.all(color: widget.appearance.borderColor), borderRadius: BorderRadius.circular(6), ), child: SingleChildScrollView( @@ -77,10 +77,12 @@ class _OpenTextQuestionState extends State { textAlignVertical: TextAlignVertical.top, decoration: InputDecoration( hintText: 'Start typing...', - hintStyle: TextStyle(color: Colors.grey.shade600), + hintStyle: TextStyle( + color: widget.appearance.inputPlaceholderColor), contentPadding: const EdgeInsets.all(12), border: InputBorder.none, ), + style: TextStyle(color: widget.appearance.inputTextColor), onChanged: (value) { setState(() { _response = value; diff --git a/lib/src/surveys/widgets/question_header.dart b/lib/src/surveys/widgets/question_header.dart index 9e608de4..ed76b8cf 100644 --- a/lib/src/surveys/widgets/question_header.dart +++ b/lib/src/surveys/widgets/question_header.dart @@ -27,7 +27,7 @@ class QuestionHeader extends StatelessWidget { style: TextStyle( fontSize: 18, fontWeight: FontWeight.bold, - color: Colors.black, + color: appearance.questionTextColor, ), ), ], @@ -39,7 +39,7 @@ class QuestionHeader extends StatelessWidget { description!, style: TextStyle( fontSize: 16, - color: appearance.descriptionTextColor ?? Colors.black, + color: appearance.descriptionTextColor, ), ), ], diff --git a/lib/src/surveys/widgets/rating_icons.dart b/lib/src/surveys/widgets/rating_icons.dart index 60f9966e..c17790fe 100644 --- a/lib/src/surveys/widgets/rating_icons.dart +++ b/lib/src/surveys/widgets/rating_icons.dart @@ -445,14 +445,14 @@ enum RatingIconType { class RatingIcon extends StatelessWidget { final bool selected; final RatingIconType type; - final Color? color; + final Color color; final double size; const RatingIcon({ super.key, required this.type, this.selected = false, - this.color, + required this.color, this.size = 48.0, }); @@ -465,7 +465,7 @@ class RatingIcon extends StatelessWidget { painter: RatingIconPainter( selected: selected, type: type, - color: color ?? Theme.of(context).iconTheme.color ?? Colors.grey, + color: color, ), ), ); diff --git a/lib/src/surveys/widgets/rating_question.dart b/lib/src/surveys/widgets/rating_question.dart index 200327a0..8b9b85bf 100644 --- a/lib/src/surveys/widgets/rating_question.dart +++ b/lib/src/surveys/widgets/rating_question.dart @@ -112,8 +112,9 @@ class _RatingQuestionState extends State { final range = widget.scaleUpperBound - widget.scaleLowerBound + 1; if (widget.type == PostHogDisplaySurveyRatingType.emoji && (range == 3 || range == 5)) { - final buttonColor = - isSelected ? Colors.black : Colors.black.withAlpha(128); + final buttonColor = isSelected + ? widget.appearance.choiceButtonTextColor + : widget.appearance.choiceButtonTextColor.withAlpha(128); // Convert value to 0-based index. // When scaleLowerBound is zero (NPS), the index is the same as the value. final index = value - widget.scaleLowerBound; @@ -163,10 +164,10 @@ class _RatingQuestionState extends State { else Container( decoration: BoxDecoration( - color: Colors.white, + color: widget.appearance.inputBackgroundColor, borderRadius: BorderRadius.circular(6), border: Border.all( - color: widget.appearance.borderColor ?? Colors.grey.shade400, + color: widget.appearance.borderColor, width: 2, ), ), diff --git a/lib/src/surveys/widgets/survey_bottom_sheet.dart b/lib/src/surveys/widgets/survey_bottom_sheet.dart index 024333d0..0f7d0450 100644 --- a/lib/src/surveys/widgets/survey_bottom_sheet.dart +++ b/lib/src/surveys/widgets/survey_bottom_sheet.dart @@ -182,7 +182,7 @@ class _SurveyBottomSheetState extends State { }, child: Container( decoration: BoxDecoration( - color: widget.appearance.backgroundColor ?? Colors.white, + color: widget.appearance.backgroundColor, borderRadius: const BorderRadius.vertical(top: Radius.circular(16)), ), child: SafeArea( @@ -201,7 +201,8 @@ class _SurveyBottomSheetState extends State { mainAxisAlignment: MainAxisAlignment.end, children: [ IconButton( - icon: const Icon(Icons.close), + icon: Icon(Icons.close, + color: widget.appearance.closeButtonColor), onPressed: () => _handleClose(), ), ], diff --git a/lib/src/surveys/widgets/survey_choice_button.dart b/lib/src/surveys/widgets/survey_choice_button.dart index 33174208..bfa777b3 100644 --- a/lib/src/surveys/widgets/survey_choice_button.dart +++ b/lib/src/surveys/widgets/survey_choice_button.dart @@ -32,8 +32,8 @@ class SurveyChoiceButton extends StatelessWidget { decoration: BoxDecoration( border: Border.all( color: isSelected - ? Colors.black - : Colors.black.withValues(alpha: 0.5), + ? appearance.choiceButtonBorderColor + : appearance.choiceButtonBorderColor.withValues(alpha: 0.5), width: 1, ), borderRadius: BorderRadius.circular(4), @@ -50,8 +50,9 @@ class SurveyChoiceButton extends StatelessWidget { '$label:', style: TextStyle( color: isSelected - ? Colors.black - : Colors.black.withAlpha(128), + ? appearance.choiceButtonTextColor + : appearance.choiceButtonTextColor + .withAlpha(128), fontWeight: isSelected ? FontWeight.bold : null, ), ), @@ -68,8 +69,9 @@ class SurveyChoiceButton extends StatelessWidget { ), style: TextStyle( color: isSelected - ? Colors.black - : Colors.black.withAlpha(128), + ? appearance.choiceButtonTextColor + : appearance.choiceButtonTextColor + .withAlpha(128), fontSize: 14, ), ), @@ -86,10 +88,10 @@ class SurveyChoiceButton extends StatelessWidget { ), ), if (isSelected) - const Icon( + Icon( Icons.check, size: 16, - color: Colors.black, + color: appearance.choiceButtonTextColor, ), ], ), From 86f671e9ad773567fd4bd11703d272251ca2df11 Mon Sep 17 00:00:00 2001 From: Adam Bowker Date: Mon, 19 Jan 2026 11:48:09 -0800 Subject: [PATCH 2/3] add auto-contrast and support for textColor, inputBackground, and inputTextColor --- CHANGELOG.md | 3 + ios/Classes/PostHogDisplaySurvey+Dict.swift | 9 +++ ios/posthog_flutter.podspec | 4 +- .../models/posthog_display_survey.dart | 3 + .../posthog_display_survey_appearance.dart | 6 ++ lib/src/surveys/models/survey_appearance.dart | 75 ++++++++++++++----- .../surveys/widgets/survey_choice_button.dart | 6 +- 7 files changed, 82 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9683479a..045e4416 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ # 5.12.0 - feat: flutter error tracking support for web ([#243](https://github.com/PostHog/posthog-flutter/pull/243)) + +- chore: improve survey color handling ([#233](https://github.com/PostHog/posthog-flutter/pull/233)) + - feat: add `userProperties` and `userPropertiesSetOnce` parameters to `capture()` method ([#254](https://github.com/PostHog/posthog-flutter/pull/254)) # 5.11.1 diff --git a/ios/Classes/PostHogDisplaySurvey+Dict.swift b/ios/Classes/PostHogDisplaySurvey+Dict.swift index 6c2e961e..c9912d62 100644 --- a/ios/Classes/PostHogDisplaySurvey+Dict.swift +++ b/ios/Classes/PostHogDisplaySurvey+Dict.swift @@ -69,6 +69,9 @@ if let submitButtonTextColor = appearance.submitButtonTextColor { appearanceDict["submitButtonTextColor"] = submitButtonTextColor } + if let textColor = appearance.textColor { + appearanceDict["textColor"] = textColor + } if let descriptionTextColor = appearance.descriptionTextColor { appearanceDict["descriptionTextColor"] = descriptionTextColor } @@ -78,6 +81,12 @@ if let ratingButtonActiveColor = appearance.ratingButtonActiveColor { appearanceDict["ratingButtonActiveColor"] = ratingButtonActiveColor } + if let inputBackground = appearance.inputBackground { + appearanceDict["inputBackground"] = inputBackground + } + if let inputTextColor = appearance.inputTextColor { + appearanceDict["inputTextColor"] = inputTextColor + } if let placeholder = appearance.placeholder { appearanceDict["placeholder"] = placeholder } diff --git a/ios/posthog_flutter.podspec b/ios/posthog_flutter.podspec index 8771ce0f..4f5f2e17 100644 --- a/ios/posthog_flutter.podspec +++ b/ios/posthog_flutter.podspec @@ -21,8 +21,8 @@ Postog flutter plugin s.ios.dependency 'Flutter' s.osx.dependency 'FlutterMacOS' - # ~> Version 3.32.0 up to, but not including, 4.0.0 - s.dependency 'PostHog', '>= 3.32.0', '< 4.0.0' + # ~> Version 3.38.0 up to, but not including, 4.0.0 + s.dependency 'PostHog', '>= 3.38.0', '< 4.0.0' s.ios.deployment_target = '13.0' # PH iOS SDK 3.0.0 requires >= 10.15 diff --git a/lib/src/surveys/models/posthog_display_survey.dart b/lib/src/surveys/models/posthog_display_survey.dart index 5c8c5cfb..1a2c0214 100644 --- a/lib/src/surveys/models/posthog_display_survey.dart +++ b/lib/src/surveys/models/posthog_display_survey.dart @@ -100,9 +100,12 @@ class PostHogDisplaySurvey { submitButtonColor: a['submitButtonColor'] as String?, submitButtonText: a['submitButtonText'] as String?, submitButtonTextColor: a['submitButtonTextColor'] as String?, + textColor: a['textColor'] as String?, descriptionTextColor: a['descriptionTextColor'] as String?, ratingButtonColor: a['ratingButtonColor'] as String?, ratingButtonActiveColor: a['ratingButtonActiveColor'] as String?, + inputBackground: a['inputBackground'] as String?, + inputTextColor: a['inputTextColor'] as String?, placeholder: a['placeholder'] as String?, displayThankYouMessage: a['displayThankYouMessage'] as bool? ?? true, thankYouMessageHeader: a['thankYouMessageHeader'] as String?, diff --git a/lib/src/surveys/models/posthog_display_survey_appearance.dart b/lib/src/surveys/models/posthog_display_survey_appearance.dart index 40ce961c..00c6e531 100644 --- a/lib/src/surveys/models/posthog_display_survey_appearance.dart +++ b/lib/src/surveys/models/posthog_display_survey_appearance.dart @@ -11,9 +11,12 @@ class PostHogDisplaySurveyAppearance { this.submitButtonColor, this.submitButtonText, this.submitButtonTextColor, + this.textColor, this.descriptionTextColor, this.ratingButtonColor, this.ratingButtonActiveColor, + this.inputBackground, + this.inputTextColor, this.placeholder, this.displayThankYouMessage = true, this.thankYouMessageHeader, @@ -28,9 +31,12 @@ class PostHogDisplaySurveyAppearance { final String? submitButtonColor; final String? submitButtonText; final String? submitButtonTextColor; + final String? textColor; final String? descriptionTextColor; final String? ratingButtonColor; final String? ratingButtonActiveColor; + final String? inputBackground; + final String? inputTextColor; final String? placeholder; final bool displayThankYouMessage; final String? thankYouMessageHeader; diff --git a/lib/src/surveys/models/survey_appearance.dart b/lib/src/surveys/models/survey_appearance.dart index aa737e41..e9562c05 100644 --- a/lib/src/surveys/models/survey_appearance.dart +++ b/lib/src/surveys/models/survey_appearance.dart @@ -1,3 +1,5 @@ +import 'dart:math' show sqrt; + import 'package:flutter/material.dart'; import 'posthog_display_survey_appearance.dart'; @@ -53,24 +55,45 @@ class SurveyAppearance { /// Creates a [SurveyAppearance] from a [PostHogDisplaySurveyAppearance] static SurveyAppearance fromPostHog( PostHogDisplaySurveyAppearance? appearance) { + final backgroundColor = + _colorFromHex(appearance?.backgroundColor) ?? Colors.white; + final submitButtonColor = + _colorFromHex(appearance?.submitButtonColor) ?? Colors.black; + final ratingButtonColor = + _colorFromHex(appearance?.ratingButtonColor) ?? const Color(0xFFEEEEEE); + final ratingButtonActiveColor = + _colorFromHex(appearance?.ratingButtonActiveColor) ?? Colors.black; + + // Input background: use override, or slight adjustment for high luminance backgrounds + final inputBackgroundColor = _colorFromHex(appearance?.inputBackground) ?? + (backgroundColor.computeLuminance() > 0.95 + ? const Color(0xFFF8F8F8) + : backgroundColor); + + // Primary text color: use textColor override if provided, otherwise auto-contrast + final primaryTextColor = _colorFromHex(appearance?.textColor) ?? + _getContrastingTextColor(backgroundColor); + + // Input text color: use override if provided, otherwise auto-contrast from input background + final inputTextColor = _colorFromHex(appearance?.inputTextColor) ?? + _getContrastingTextColor(inputBackgroundColor); + return SurveyAppearance( - backgroundColor: - _colorFromHex(appearance?.backgroundColor) ?? Colors.white, - submitButtonColor: - _colorFromHex(appearance?.submitButtonColor) ?? Colors.black, + backgroundColor: backgroundColor, + submitButtonColor: submitButtonColor, submitButtonText: appearance?.submitButtonText ?? 'Submit', submitButtonTextColor: - _colorFromHex(appearance?.submitButtonTextColor) ?? Colors.white, + _colorFromHex(appearance?.submitButtonTextColor) ?? + _getContrastingTextColor(submitButtonColor), descriptionTextColor: - _colorFromHex(appearance?.descriptionTextColor) ?? Colors.black, - questionTextColor: Colors.black, - closeButtonColor: Colors.black, - ratingButtonColor: _colorFromHex(appearance?.ratingButtonColor) ?? - const Color(0xFFEEEEEE), - ratingButtonActiveColor: - _colorFromHex(appearance?.ratingButtonActiveColor) ?? Colors.black, - ratingButtonSelectedTextColor: Colors.white, - ratingButtonUnselectedTextColor: const Color(0x80000000), + _colorFromHex(appearance?.descriptionTextColor) ?? primaryTextColor, + questionTextColor: primaryTextColor, + closeButtonColor: primaryTextColor, + ratingButtonColor: ratingButtonColor, + ratingButtonActiveColor: ratingButtonActiveColor, + ratingButtonSelectedTextColor: + _getContrastingTextColor(ratingButtonActiveColor), + ratingButtonUnselectedTextColor: inputTextColor.withAlpha(128), displayThankYouMessage: appearance?.displayThankYouMessage ?? true, thankYouMessageHeader: appearance?.thankYouMessageHeader ?? 'Thank you for your feedback!', @@ -79,14 +102,28 @@ class SurveyAppearance { appearance?.thankYouMessageCloseButtonText ?? 'Close', borderColor: _colorFromHex(appearance?.borderColor) ?? const Color(0xFFBDBDBD), - inputBackgroundColor: Colors.white, - inputTextColor: Colors.black, - inputPlaceholderColor: const Color(0xFF757575), - choiceButtonBorderColor: Colors.black, - choiceButtonTextColor: Colors.black, + inputBackgroundColor: inputBackgroundColor, + inputTextColor: inputTextColor, + inputPlaceholderColor: inputTextColor.withAlpha(153), + choiceButtonBorderColor: primaryTextColor, + choiceButtonTextColor: primaryTextColor, ); } + /// Returns black or white text color based on the perceived brightness of the background. + /// 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; + // 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) + return hsp > 127.5 ? Colors.black : Colors.white; + } + static Color? _colorFromHex(String? colorString) { if (colorString == null || colorString.isEmpty) return null; diff --git a/lib/src/surveys/widgets/survey_choice_button.dart b/lib/src/surveys/widgets/survey_choice_button.dart index bfa777b3..adf21363 100644 --- a/lib/src/surveys/widgets/survey_choice_button.dart +++ b/lib/src/surveys/widgets/survey_choice_button.dart @@ -52,7 +52,7 @@ class SurveyChoiceButton extends StatelessWidget { color: isSelected ? appearance.choiceButtonTextColor : appearance.choiceButtonTextColor - .withAlpha(128), + .withValues(alpha: 0.5), fontWeight: isSelected ? FontWeight.bold : null, ), ), @@ -71,7 +71,7 @@ class SurveyChoiceButton extends StatelessWidget { color: isSelected ? appearance.choiceButtonTextColor : appearance.choiceButtonTextColor - .withAlpha(128), + .withValues(alpha: 0.5), fontSize: 14, ), ), @@ -82,7 +82,7 @@ class SurveyChoiceButton extends StatelessWidget { style: TextStyle( color: isSelected ? Colors.black - : Colors.black.withAlpha(128), + : Colors.black.withValues(alpha: 0.5), fontWeight: isSelected ? FontWeight.bold : null, ), ), From 9fc66696327389283e0b76cb58b6013a188c5dab Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Fri, 23 Jan 2026 15:38:30 -0300 Subject: [PATCH 3/3] fix --- CHANGELOG.md | 5 ++--- android/build.gradle | 4 ++-- .../kotlin/com/posthog/flutter/PostHogDisplaySurveyExt.kt | 7 ++++++- lib/src/surveys/models/survey_appearance.dart | 8 +++----- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 045e4416..6d600515 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## Next +- chore: improve survey color handling ([#233](https://github.com/PostHog/posthog-flutter/pull/233)) + - feat: add `beforeSend` callback to `PostHogConfig` for dropping or modifying events before they are sent to PostHog ([#255](https://github.com/PostHog/posthog-flutter/pull/255)) - **Limitation**: - Does NOT intercept native-initiated events such as: @@ -14,9 +16,6 @@ # 5.12.0 - feat: flutter error tracking support for web ([#243](https://github.com/PostHog/posthog-flutter/pull/243)) - -- chore: improve survey color handling ([#233](https://github.com/PostHog/posthog-flutter/pull/233)) - - feat: add `userProperties` and `userPropertiesSetOnce` parameters to `capture()` method ([#254](https://github.com/PostHog/posthog-flutter/pull/254)) # 5.11.1 diff --git a/android/build.gradle b/android/build.gradle index ff118251..7c20f520 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -53,8 +53,8 @@ android { dependencies { testImplementation 'org.jetbrains.kotlin:kotlin-test' testImplementation 'org.mockito:mockito-core:5.0.0' - // + Version 3.25.0 and the versions up to 4.0.0, not including 4.0.0 and higher - implementation 'com.posthog:posthog-android:[3.25.0,4.0.0]' + // + Version 3.30.0 and the versions up to 4.0.0, not including 4.0.0 and higher + implementation 'com.posthog:posthog-android:[3.30.0,4.0.0]' } testOptions { diff --git a/android/src/main/kotlin/com/posthog/flutter/PostHogDisplaySurveyExt.kt b/android/src/main/kotlin/com/posthog/flutter/PostHogDisplaySurveyExt.kt index d8a64350..6f58302d 100644 --- a/android/src/main/kotlin/com/posthog/flutter/PostHogDisplaySurveyExt.kt +++ b/android/src/main/kotlin/com/posthog/flutter/PostHogDisplaySurveyExt.kt @@ -60,19 +60,24 @@ fun PostHogDisplaySurvey.toMap(): Map { appearance?.let { app -> map["appearance"] = mapOf( + "fontFamily" to app.fontFamily, "backgroundColor" to app.backgroundColor, + "borderColor" to app.borderColor, "submitButtonColor" to app.submitButtonColor, "submitButtonText" to app.submitButtonText, "submitButtonTextColor" to app.submitButtonTextColor, + "textColor" to app.textColor, "descriptionTextColor" to app.descriptionTextColor, "ratingButtonColor" to app.ratingButtonColor, "ratingButtonActiveColor" to app.ratingButtonActiveColor, - "borderColor" to app.borderColor, + "inputBackground" to app.inputBackground, + "inputTextColor" to app.inputTextColor, "placeholder" to app.placeholder, "displayThankYouMessage" to app.displayThankYouMessage, "thankYouMessageHeader" to app.thankYouMessageHeader, "thankYouMessageDescription" to app.thankYouMessageDescription, "thankYouMessageDescriptionContentType" to app.thankYouMessageDescriptionContentType?.value, + "thankYouMessageCloseButtonText" to app.thankYouMessageCloseButtonText, ) } diff --git a/lib/src/surveys/models/survey_appearance.dart b/lib/src/surveys/models/survey_appearance.dart index e9562c05..4feaf296 100644 --- a/lib/src/surveys/models/survey_appearance.dart +++ b/lib/src/surveys/models/survey_appearance.dart @@ -82,9 +82,8 @@ class SurveyAppearance { backgroundColor: backgroundColor, submitButtonColor: submitButtonColor, submitButtonText: appearance?.submitButtonText ?? 'Submit', - submitButtonTextColor: - _colorFromHex(appearance?.submitButtonTextColor) ?? - _getContrastingTextColor(submitButtonColor), + submitButtonTextColor: _colorFromHex(appearance?.submitButtonTextColor) ?? + _getContrastingTextColor(submitButtonColor), descriptionTextColor: _colorFromHex(appearance?.descriptionTextColor) ?? primaryTextColor, questionTextColor: primaryTextColor, @@ -118,8 +117,7 @@ class SurveyAppearance { final g = color.green; final b = color.blue; // HSP equation for perceived brightness - final hsp = - sqrt(0.299 * (r * r) + 0.587 * (g * g) + 0.114 * (b * b)); + final hsp = sqrt(0.299 * (r * r) + 0.587 * (g * g) + 0.114 * (b * b)); // Using 127.5 as threshold (same as JS) return hsp > 127.5 ? Colors.black : Colors.white; }