Skip to content

Commit 3e75325

Browse files
committed
Improve consistency when handling colors in surveys.
Co-authored-by: Tate <wintermydog@gmail.com>
1 parent d8e3b60 commit 3e75325

File tree

8 files changed

+79
-42
lines changed

8 files changed

+79
-42
lines changed

lib/src/surveys/models/survey_appearance.dart

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,85 @@ import 'posthog_display_survey_appearance.dart';
55
@immutable
66
class SurveyAppearance {
77
const SurveyAppearance({
8-
this.backgroundColor,
8+
this.backgroundColor = Colors.white,
99
this.submitButtonColor = Colors.black,
1010
this.submitButtonText = 'Submit',
1111
this.submitButtonTextColor = Colors.white,
12-
this.descriptionTextColor,
13-
this.ratingButtonColor,
14-
this.ratingButtonActiveColor,
12+
this.descriptionTextColor = Colors.black,
13+
this.questionTextColor = Colors.black,
14+
this.closeButtonColor = Colors.black,
15+
this.ratingButtonColor = const Color(0xFFEEEEEE),
16+
this.ratingButtonActiveColor = Colors.black,
17+
this.ratingButtonSelectedTextColor = Colors.white,
18+
this.ratingButtonUnselectedTextColor = const Color(0x80000000),
1519
this.displayThankYouMessage = true,
1620
this.thankYouMessageHeader = 'Thank you for your feedback!',
1721
this.thankYouMessageDescription,
1822
this.thankYouMessageCloseButtonText = 'Close',
19-
this.borderColor,
23+
this.borderColor = const Color(0xFFBDBDBD),
24+
this.inputBackgroundColor = Colors.white,
25+
this.inputTextColor = Colors.black,
26+
this.inputPlaceholderColor = const Color(0xFF757575),
27+
this.choiceButtonBorderColor = Colors.black,
28+
this.choiceButtonTextColor = Colors.black,
2029
});
2130

22-
final Color? backgroundColor;
31+
final Color backgroundColor;
2332
final Color submitButtonColor;
2433
final String submitButtonText;
2534
final Color submitButtonTextColor;
26-
final Color? descriptionTextColor;
27-
final Color? ratingButtonColor;
28-
final Color? ratingButtonActiveColor;
35+
final Color descriptionTextColor;
36+
final Color questionTextColor;
37+
final Color closeButtonColor;
38+
final Color ratingButtonColor;
39+
final Color ratingButtonActiveColor;
40+
final Color ratingButtonSelectedTextColor;
41+
final Color ratingButtonUnselectedTextColor;
2942
final bool displayThankYouMessage;
3043
final String thankYouMessageHeader;
3144
final String? thankYouMessageDescription;
3245
final String thankYouMessageCloseButtonText;
33-
final Color? borderColor;
46+
final Color borderColor;
47+
final Color inputBackgroundColor;
48+
final Color inputTextColor;
49+
final Color inputPlaceholderColor;
50+
final Color choiceButtonBorderColor;
51+
final Color choiceButtonTextColor;
3452

3553
/// Creates a [SurveyAppearance] from a [PostHogDisplaySurveyAppearance]
3654
static SurveyAppearance fromPostHog(
3755
PostHogDisplaySurveyAppearance? appearance) {
3856
return SurveyAppearance(
39-
backgroundColor: _colorFromHex(appearance?.backgroundColor),
57+
backgroundColor:
58+
_colorFromHex(appearance?.backgroundColor) ?? Colors.white,
4059
submitButtonColor:
4160
_colorFromHex(appearance?.submitButtonColor) ?? Colors.black,
4261
submitButtonText: appearance?.submitButtonText ?? 'Submit',
4362
submitButtonTextColor:
4463
_colorFromHex(appearance?.submitButtonTextColor) ?? Colors.white,
45-
descriptionTextColor: _colorFromHex(appearance?.descriptionTextColor),
46-
ratingButtonColor: _colorFromHex(appearance?.ratingButtonColor),
64+
descriptionTextColor:
65+
_colorFromHex(appearance?.descriptionTextColor) ?? Colors.black,
66+
questionTextColor: Colors.black,
67+
closeButtonColor: Colors.black,
68+
ratingButtonColor: _colorFromHex(appearance?.ratingButtonColor) ??
69+
const Color(0xFFEEEEEE),
4770
ratingButtonActiveColor:
48-
_colorFromHex(appearance?.ratingButtonActiveColor),
71+
_colorFromHex(appearance?.ratingButtonActiveColor) ?? Colors.black,
72+
ratingButtonSelectedTextColor: Colors.white,
73+
ratingButtonUnselectedTextColor: const Color(0x80000000),
4974
displayThankYouMessage: appearance?.displayThankYouMessage ?? true,
5075
thankYouMessageHeader:
5176
appearance?.thankYouMessageHeader ?? 'Thank you for your feedback!',
5277
thankYouMessageDescription: appearance?.thankYouMessageDescription,
5378
thankYouMessageCloseButtonText:
5479
appearance?.thankYouMessageCloseButtonText ?? 'Close',
55-
borderColor: _colorFromHex(appearance?.borderColor),
80+
borderColor:
81+
_colorFromHex(appearance?.borderColor) ?? const Color(0xFFBDBDBD),
82+
inputBackgroundColor: Colors.white,
83+
inputTextColor: Colors.black,
84+
inputPlaceholderColor: const Color(0xFF757575),
85+
choiceButtonBorderColor: Colors.black,
86+
choiceButtonTextColor: Colors.black,
5687
);
5788
}
5889

lib/src/surveys/widgets/number_rating_button.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class NumberRatingButton extends StatelessWidget {
2222
@override
2323
Widget build(BuildContext context) {
2424
final buttonColor = isSelected
25-
? appearance.ratingButtonActiveColor ?? Colors.black
26-
: appearance.ratingButtonColor ?? Colors.grey.shade200;
25+
? appearance.ratingButtonActiveColor
26+
: appearance.ratingButtonColor;
2727

2828
return Expanded(
2929
child: Row(
@@ -61,8 +61,8 @@ class NumberRatingButton extends StatelessWidget {
6161
value.toString(),
6262
style: TextStyle(
6363
color: isSelected
64-
? Colors.white
65-
: Colors.black.withValues(alpha: 0.5),
64+
? appearance.ratingButtonSelectedTextColor
65+
: appearance.ratingButtonUnselectedTextColor,
6666
fontSize: 16,
6767
fontWeight: FontWeight.bold,
6868
),
@@ -78,7 +78,7 @@ class NumberRatingButton extends StatelessWidget {
7878
Container(
7979
height: 45,
8080
width: 1,
81-
color: appearance.borderColor ?? Colors.grey.shade400,
81+
color: appearance.borderColor,
8282
),
8383
],
8484
),

lib/src/surveys/widgets/open_text_question.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ class _OpenTextQuestionState extends State<OpenTextQuestion> {
6666
minHeight: 80,
6767
),
6868
decoration: BoxDecoration(
69-
color: Colors.white,
70-
border: Border.all(color: Colors.grey.shade400),
69+
color: widget.appearance.inputBackgroundColor,
70+
border: Border.all(color: widget.appearance.borderColor),
7171
borderRadius: BorderRadius.circular(6),
7272
),
7373
child: SingleChildScrollView(
@@ -77,10 +77,12 @@ class _OpenTextQuestionState extends State<OpenTextQuestion> {
7777
textAlignVertical: TextAlignVertical.top,
7878
decoration: InputDecoration(
7979
hintText: 'Start typing...',
80-
hintStyle: TextStyle(color: Colors.grey.shade600),
80+
hintStyle: TextStyle(
81+
color: widget.appearance.inputPlaceholderColor),
8182
contentPadding: const EdgeInsets.all(12),
8283
border: InputBorder.none,
8384
),
85+
style: TextStyle(color: widget.appearance.inputTextColor),
8486
onChanged: (value) {
8587
setState(() {
8688
_response = value;

lib/src/surveys/widgets/question_header.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class QuestionHeader extends StatelessWidget {
2727
style: TextStyle(
2828
fontSize: 18,
2929
fontWeight: FontWeight.bold,
30-
color: Colors.black,
30+
color: appearance.questionTextColor,
3131
),
3232
),
3333
],
@@ -39,7 +39,7 @@ class QuestionHeader extends StatelessWidget {
3939
description!,
4040
style: TextStyle(
4141
fontSize: 16,
42-
color: appearance.descriptionTextColor ?? Colors.black,
42+
color: appearance.descriptionTextColor,
4343
),
4444
),
4545
],

lib/src/surveys/widgets/rating_icons.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,14 +445,14 @@ enum RatingIconType {
445445
class RatingIcon extends StatelessWidget {
446446
final bool selected;
447447
final RatingIconType type;
448-
final Color? color;
448+
final Color color;
449449
final double size;
450450

451451
const RatingIcon({
452452
super.key,
453453
required this.type,
454454
this.selected = false,
455-
this.color,
455+
required this.color,
456456
this.size = 48.0,
457457
});
458458

@@ -465,7 +465,7 @@ class RatingIcon extends StatelessWidget {
465465
painter: RatingIconPainter(
466466
selected: selected,
467467
type: type,
468-
color: color ?? Theme.of(context).iconTheme.color ?? Colors.grey,
468+
color: color,
469469
),
470470
),
471471
);

lib/src/surveys/widgets/rating_question.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ class _RatingQuestionState extends State<RatingQuestion> {
112112
final range = widget.scaleUpperBound - widget.scaleLowerBound + 1;
113113
if (widget.type == PostHogDisplaySurveyRatingType.emoji &&
114114
(range == 3 || range == 5)) {
115-
final buttonColor =
116-
isSelected ? Colors.black : Colors.black.withAlpha(128);
115+
final buttonColor = isSelected
116+
? widget.appearance.choiceButtonTextColor
117+
: widget.appearance.choiceButtonTextColor.withAlpha(128);
117118
// Convert value to 0-based index.
118119
// When scaleLowerBound is zero (NPS), the index is the same as the value.
119120
final index = value - widget.scaleLowerBound;
@@ -163,10 +164,10 @@ class _RatingQuestionState extends State<RatingQuestion> {
163164
else
164165
Container(
165166
decoration: BoxDecoration(
166-
color: Colors.white,
167+
color: widget.appearance.inputBackgroundColor,
167168
borderRadius: BorderRadius.circular(6),
168169
border: Border.all(
169-
color: widget.appearance.borderColor ?? Colors.grey.shade400,
170+
color: widget.appearance.borderColor,
170171
width: 2,
171172
),
172173
),

lib/src/surveys/widgets/survey_bottom_sheet.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class _SurveyBottomSheetState extends State<SurveyBottomSheet> {
182182
},
183183
child: Container(
184184
decoration: BoxDecoration(
185-
color: widget.appearance.backgroundColor ?? Colors.white,
185+
color: widget.appearance.backgroundColor,
186186
borderRadius: const BorderRadius.vertical(top: Radius.circular(16)),
187187
),
188188
child: SafeArea(
@@ -201,7 +201,8 @@ class _SurveyBottomSheetState extends State<SurveyBottomSheet> {
201201
mainAxisAlignment: MainAxisAlignment.end,
202202
children: [
203203
IconButton(
204-
icon: const Icon(Icons.close),
204+
icon: Icon(Icons.close,
205+
color: widget.appearance.closeButtonColor),
205206
onPressed: () => _handleClose(),
206207
),
207208
],

lib/src/surveys/widgets/survey_choice_button.dart

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class SurveyChoiceButton extends StatelessWidget {
3232
decoration: BoxDecoration(
3333
border: Border.all(
3434
color: isSelected
35-
? Colors.black
36-
: Colors.black.withValues(alpha: 0.5),
35+
? appearance.choiceButtonBorderColor
36+
: appearance.choiceButtonBorderColor.withValues(alpha: 0.5),
3737
width: 1,
3838
),
3939
borderRadius: BorderRadius.circular(4),
@@ -50,8 +50,9 @@ class SurveyChoiceButton extends StatelessWidget {
5050
'$label:',
5151
style: TextStyle(
5252
color: isSelected
53-
? Colors.black
54-
: Colors.black.withAlpha(128),
53+
? appearance.choiceButtonTextColor
54+
: appearance.choiceButtonTextColor
55+
.withAlpha(128),
5556
fontWeight: isSelected ? FontWeight.bold : null,
5657
),
5758
),
@@ -68,8 +69,9 @@ class SurveyChoiceButton extends StatelessWidget {
6869
),
6970
style: TextStyle(
7071
color: isSelected
71-
? Colors.black
72-
: Colors.black.withAlpha(128),
72+
? appearance.choiceButtonTextColor
73+
: appearance.choiceButtonTextColor
74+
.withAlpha(128),
7375
fontSize: 14,
7476
),
7577
),
@@ -86,10 +88,10 @@ class SurveyChoiceButton extends StatelessWidget {
8688
),
8789
),
8890
if (isSelected)
89-
const Icon(
91+
Icon(
9092
Icons.check,
9193
size: 16,
92-
color: Colors.black,
94+
color: appearance.choiceButtonTextColor,
9395
),
9496
],
9597
),

0 commit comments

Comments
 (0)