Skip to content

Commit

Permalink
emoji_reaction [nfc]: Make EmojiReactionTheme.{light,dark} static finals
Browse files Browse the repository at this point in the history
Like we did for MessageListTheme in the previous commit and
DesignVariables in dcc8123.
  • Loading branch information
chrisbobbe committed Jan 18, 2025
1 parent 255e4d9 commit 34b31da
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 39 deletions.
62 changes: 30 additions & 32 deletions lib/widgets/emoji_reaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,36 @@ import 'theme.dart';

/// Emoji-reaction styles that differ between light and dark themes.
class EmojiReactionTheme extends ThemeExtension<EmojiReactionTheme> {
EmojiReactionTheme.light() :
this._(
bgSelected: Colors.white,

// TODO shadow effect, following web, which uses `box-shadow: inset`:
// https://developer.mozilla.org/en-US/docs/Web/CSS/box-shadow#inset
// Needs Flutter support for something like that:
// https://github.com/flutter/flutter/issues/18636
// https://github.com/flutter/flutter/issues/52999
// Until then use a solid color; a much-lightened version of the shadow color.
// Also adapt by making [borderUnselected] more transparent, so we'll
// want to check that against web when implementing the shadow.
bgUnselected: const HSLColor.fromAHSL(0.08, 210, 0.50, 0.875).toColor(),

borderSelected: Colors.black.withValues(alpha: 0.45),

// TODO see TODO on [bgUnselected] about shadow effect
borderUnselected: Colors.black.withValues(alpha: 0.05),

textSelected: const HSLColor.fromAHSL(1, 210, 0.20, 0.20).toColor(),
textUnselected: const HSLColor.fromAHSL(1, 210, 0.20, 0.25).toColor(),
);

EmojiReactionTheme.dark() :
this._(
bgSelected: Colors.black.withValues(alpha: 0.8),
bgUnselected: Colors.black.withValues(alpha: 0.3),
borderSelected: Colors.white.withValues(alpha: 0.75),
borderUnselected: Colors.white.withValues(alpha: 0.15),
textSelected: Colors.white.withValues(alpha: 0.85),
textUnselected: Colors.white.withValues(alpha: 0.75),
);
static final light = EmojiReactionTheme._(
bgSelected: Colors.white,

// TODO shadow effect, following web, which uses `box-shadow: inset`:
// https://developer.mozilla.org/en-US/docs/Web/CSS/box-shadow#inset
// Needs Flutter support for something like that:
// https://github.com/flutter/flutter/issues/18636
// https://github.com/flutter/flutter/issues/52999
// Until then use a solid color; a much-lightened version of the shadow color.
// Also adapt by making [borderUnselected] more transparent, so we'll
// want to check that against web when implementing the shadow.
bgUnselected: const HSLColor.fromAHSL(0.08, 210, 0.50, 0.875).toColor(),

borderSelected: Colors.black.withValues(alpha: 0.45),

// TODO see TODO on [bgUnselected] about shadow effect
borderUnselected: Colors.black.withValues(alpha: 0.05),

textSelected: const HSLColor.fromAHSL(1, 210, 0.20, 0.20).toColor(),
textUnselected: const HSLColor.fromAHSL(1, 210, 0.20, 0.25).toColor(),
);

static final dark = EmojiReactionTheme._(
bgSelected: Colors.black.withValues(alpha: 0.8),
bgUnselected: Colors.black.withValues(alpha: 0.3),
borderSelected: Colors.white.withValues(alpha: 0.75),
borderUnselected: Colors.white.withValues(alpha: 0.15),
textSelected: Colors.white.withValues(alpha: 0.85),
textUnselected: Colors.white.withValues(alpha: 0.75),
);

EmojiReactionTheme._({
required this.bgSelected,
Expand Down
4 changes: 2 additions & 2 deletions lib/widgets/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ThemeData zulipThemeData(BuildContext context) {
themeExtensions = [
ContentTheme.light(context),
designVariables,
EmojiReactionTheme.light(),
EmojiReactionTheme.light,
MessageListTheme.light,
];
}
Expand All @@ -39,7 +39,7 @@ ThemeData zulipThemeData(BuildContext context) {
themeExtensions = [
ContentTheme.dark(context),
designVariables,
EmojiReactionTheme.dark(),
EmojiReactionTheme.dark,
MessageListTheme.dark,
];
}
Expand Down
10 changes: 5 additions & 5 deletions test/widgets/emoji_reaction_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -251,25 +251,25 @@ void main() {
}

check(backgroundColor('smile')).isNotNull()
.isSameColorAs(EmojiReactionTheme.light().bgSelected);
.isSameColorAs(EmojiReactionTheme.light.bgSelected);
check(backgroundColor('tada')).isNotNull()
.isSameColorAs(EmojiReactionTheme.light().bgUnselected);
.isSameColorAs(EmojiReactionTheme.light.bgUnselected);

tester.platformDispatcher.platformBrightnessTestValue = Brightness.dark;
await tester.pump();

await tester.pump(kThemeAnimationDuration * 0.4);
final expectedLerped = EmojiReactionTheme.light().lerp(EmojiReactionTheme.dark(), 0.4);
final expectedLerped = EmojiReactionTheme.light.lerp(EmojiReactionTheme.dark, 0.4);
check(backgroundColor('smile')).isNotNull()
.isSameColorAs(expectedLerped.bgSelected);
check(backgroundColor('tada')).isNotNull()
.isSameColorAs(expectedLerped.bgUnselected);

await tester.pump(kThemeAnimationDuration * 0.6);
check(backgroundColor('smile')).isNotNull()
.isSameColorAs(EmojiReactionTheme.dark().bgSelected);
.isSameColorAs(EmojiReactionTheme.dark.bgSelected);
check(backgroundColor('tada')).isNotNull()
.isSameColorAs(EmojiReactionTheme.dark().bgUnselected);
.isSameColorAs(EmojiReactionTheme.dark.bgUnselected);
});

testWidgets('use emoji font', (tester) async {
Expand Down

0 comments on commit 34b31da

Please sign in to comment.