@@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart';
22import 'package:flutter/material.dart' ;
33import 'package:stream_chat_flutter/src/theme/avatar_theme.dart' ;
44import 'package:stream_chat_flutter/src/theme/stream_chat_theme.dart' ;
5+ import 'package:stream_chat_flutter/src/utils/date_formatter.dart' ;
56
67/// {@template channelPreviewTheme}
78/// Overrides the default style of [ChannelPreview] descendants.
@@ -70,6 +71,7 @@ class StreamChannelPreviewThemeData with Diagnosticable {
7071 this .avatarTheme,
7172 this .unreadCounterColor,
7273 this .indicatorIconSize,
74+ this .lastMessageAtFormatter,
7375 });
7476
7577 /// Theme for title
@@ -90,6 +92,21 @@ class StreamChannelPreviewThemeData with Diagnosticable {
9092 /// Indicator icon size
9193 final double ? indicatorIconSize;
9294
95+ /// Formatter for the last message timestamp.
96+ ///
97+ /// If null, uses the default date formatting.
98+ ///
99+ /// Example:
100+ /// ```dart
101+ /// StreamChannelPreviewThemeData(
102+ /// lastMessageAtStyle: TextStyle(...),
103+ /// lastMessageAtFormatter: (context, date) {
104+ /// return Jiffy.parseFromDateTime(date).format('d MMMM'); // "23 May"
105+ /// },
106+ /// )
107+ /// ```
108+ final DateFormatter ? lastMessageAtFormatter;
109+
93110 /// Copy with theme
94111 StreamChannelPreviewThemeData copyWith ({
95112 TextStyle ? titleStyle,
@@ -98,6 +115,7 @@ class StreamChannelPreviewThemeData with Diagnosticable {
98115 StreamAvatarThemeData ? avatarTheme,
99116 Color ? unreadCounterColor,
100117 double ? indicatorIconSize,
118+ DateFormatter ? lastMessageAtFormatter,
101119 }) {
102120 return StreamChannelPreviewThemeData (
103121 titleStyle: titleStyle ?? this .titleStyle,
@@ -106,6 +124,8 @@ class StreamChannelPreviewThemeData with Diagnosticable {
106124 avatarTheme: avatarTheme ?? this .avatarTheme,
107125 unreadCounterColor: unreadCounterColor ?? this .unreadCounterColor,
108126 indicatorIconSize: indicatorIconSize ?? this .indicatorIconSize,
127+ lastMessageAtFormatter:
128+ lastMessageAtFormatter ?? this .lastMessageAtFormatter,
109129 );
110130 }
111131
@@ -125,6 +145,8 @@ class StreamChannelPreviewThemeData with Diagnosticable {
125145 titleStyle: TextStyle .lerp (a.titleStyle, b.titleStyle, t),
126146 unreadCounterColor:
127147 Color .lerp (a.unreadCounterColor, b.unreadCounterColor, t),
148+ lastMessageAtFormatter:
149+ t < 0.5 ? a.lastMessageAtFormatter : b.lastMessageAtFormatter,
128150 );
129151 }
130152
@@ -139,6 +161,8 @@ class StreamChannelPreviewThemeData with Diagnosticable {
139161 other.lastMessageAtStyle,
140162 avatarTheme: avatarTheme? .merge (other.avatarTheme) ?? other.avatarTheme,
141163 unreadCounterColor: other.unreadCounterColor,
164+ lastMessageAtFormatter:
165+ other.lastMessageAtFormatter ?? lastMessageAtFormatter,
142166 );
143167 }
144168
@@ -152,7 +176,8 @@ class StreamChannelPreviewThemeData with Diagnosticable {
152176 lastMessageAtStyle == other.lastMessageAtStyle &&
153177 avatarTheme == other.avatarTheme &&
154178 unreadCounterColor == other.unreadCounterColor &&
155- indicatorIconSize == other.indicatorIconSize;
179+ indicatorIconSize == other.indicatorIconSize &&
180+ lastMessageAtFormatter == other.lastMessageAtFormatter;
156181
157182 @override
158183 int get hashCode =>
@@ -161,7 +186,8 @@ class StreamChannelPreviewThemeData with Diagnosticable {
161186 lastMessageAtStyle.hashCode ^
162187 avatarTheme.hashCode ^
163188 unreadCounterColor.hashCode ^
164- indicatorIconSize.hashCode;
189+ indicatorIconSize.hashCode ^
190+ lastMessageAtFormatter.hashCode;
165191
166192 @override
167193 void debugFillProperties (DiagnosticPropertiesBuilder properties) {
@@ -171,6 +197,8 @@ class StreamChannelPreviewThemeData with Diagnosticable {
171197 ..add (DiagnosticsProperty ('subtitleStyle' , subtitleStyle))
172198 ..add (DiagnosticsProperty ('lastMessageAtStyle' , lastMessageAtStyle))
173199 ..add (DiagnosticsProperty ('avatarTheme' , avatarTheme))
174- ..add (ColorProperty ('unreadCounterColor' , unreadCounterColor));
200+ ..add (ColorProperty ('unreadCounterColor' , unreadCounterColor))
201+ ..add (DiagnosticsProperty (
202+ 'lastMessageAtFormatter' , lastMessageAtFormatter));
175203 }
176204}
0 commit comments