From d8ca465b91a496fa5bf23a53f05291aa02da611f Mon Sep 17 00:00:00 2001 From: groovinchip Date: Mon, 2 Aug 2021 09:24:17 -0400 Subject: [PATCH] chore: add lerp, == and hashCode to ChannelPreviewTheme --- .../lib/src/theme/channel_preview_theme.dart | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/packages/stream_chat_flutter/lib/src/theme/channel_preview_theme.dart b/packages/stream_chat_flutter/lib/src/theme/channel_preview_theme.dart index 023c1f0a..18783d02 100644 --- a/packages/stream_chat_flutter/lib/src/theme/channel_preview_theme.dart +++ b/packages/stream_chat_flutter/lib/src/theme/channel_preview_theme.dart @@ -50,6 +50,24 @@ class ChannelPreviewThemeData with Diagnosticable { indicatorIconSize: indicatorIconSize ?? this.indicatorIconSize, ); + /// Linearly interpolate one [ChannelPreviewThemeData] to another. + ChannelPreviewThemeData lerp( + ChannelPreviewThemeData a, + ChannelPreviewThemeData b, + double t, + ) => + ChannelPreviewThemeData( + avatarTheme: + const AvatarThemeData().lerp(a.avatarTheme!, b.avatarTheme!, t), + indicatorIconSize: a.indicatorIconSize, + lastMessageAtStyle: + TextStyle.lerp(a.lastMessageAtStyle, b.lastMessageAtStyle, t), + subtitleStyle: TextStyle.lerp(a.subtitleStyle, b.subtitleStyle, t), + titleStyle: TextStyle.lerp(a.titleStyle, b.titleStyle, t), + unreadCounterColor: + Color.lerp(a.unreadCounterColor, b.unreadCounterColor, t), + ); + /// Merge with theme ChannelPreviewThemeData merge(ChannelPreviewThemeData? other) { if (other == null) return this; @@ -64,6 +82,27 @@ class ChannelPreviewThemeData with Diagnosticable { ); } + @override + bool operator ==(Object other) => + identical(this, other) || + other is ChannelPreviewThemeData && + runtimeType == other.runtimeType && + titleStyle == other.titleStyle && + subtitleStyle == other.subtitleStyle && + lastMessageAtStyle == other.lastMessageAtStyle && + avatarTheme == other.avatarTheme && + unreadCounterColor == other.unreadCounterColor && + indicatorIconSize == other.indicatorIconSize; + + @override + int get hashCode => + titleStyle.hashCode ^ + subtitleStyle.hashCode ^ + lastMessageAtStyle.hashCode ^ + avatarTheme.hashCode ^ + unreadCounterColor.hashCode ^ + indicatorIconSize.hashCode; + @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties);