Adding custom line for url attachment

This commit is contained in:
Leandro Borges Ferreira
2023-02-02 17:42:49 +01:00
parent 4563abaaef
commit 02ab954048
3 changed files with 18 additions and 4 deletions
@@ -74,6 +74,9 @@ class MyApp extends StatelessWidget {
fit: BoxFit.cover, fit: BoxFit.cover,
), ),
), ),
ownMessageTheme: const StreamMessageThemeData(
urlLinkTitleMaxLine: 1,
),
otherMessageTheme: StreamMessageThemeData( otherMessageTheme: StreamMessageThemeData(
messageBackgroundColor: colorTheme.textHighEmphasis, messageBackgroundColor: colorTheme.textHighEmphasis,
messageTextStyle: TextStyle( messageTextStyle: TextStyle(
@@ -82,6 +85,7 @@ class MyApp extends StatelessWidget {
avatarTheme: StreamAvatarThemeData( avatarTheme: StreamAvatarThemeData(
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
), ),
urlLinkTitleMaxLine: 1,
), ),
).merge(defaultTheme); ).merge(defaultTheme);
@@ -107,7 +107,7 @@ class StreamUrlAttachment extends StatelessWidget {
if (urlAttachment.title != null) if (urlAttachment.title != null)
Text( Text(
urlAttachment.title!.trim(), urlAttachment.title!.trim(),
maxLines: 1, maxLines: messageTheme.urlLinkTitleMaxLine ?? 1,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
style: chatThemeData.textTheme.body style: chatThemeData.textTheme.body
.copyWith(fontWeight: FontWeight.w700), .copyWith(fontWeight: FontWeight.w700),
@@ -21,6 +21,7 @@ class StreamMessageThemeData with Diagnosticable {
this.avatarTheme, this.avatarTheme,
this.createdAtStyle, this.createdAtStyle,
this.linkBackgroundColor, this.linkBackgroundColor,
this.urlLinkTitleMaxLine,
}); });
/// Text style for message text /// Text style for message text
@@ -59,6 +60,9 @@ class StreamMessageThemeData with Diagnosticable {
/// Background color for messages with url attachments. /// Background color for messages with url attachments.
final Color? linkBackgroundColor; final Color? linkBackgroundColor;
/// Max number of lines in Url link title
final int? urlLinkTitleMaxLine;
/// Copy with a theme /// Copy with a theme
StreamMessageThemeData copyWith({ StreamMessageThemeData copyWith({
TextStyle? messageTextStyle, TextStyle? messageTextStyle,
@@ -73,6 +77,7 @@ class StreamMessageThemeData with Diagnosticable {
Color? reactionsBorderColor, Color? reactionsBorderColor,
Color? reactionsMaskColor, Color? reactionsMaskColor,
Color? linkBackgroundColor, Color? linkBackgroundColor,
int? urlLinkTitleMaxLine,
}) { }) {
return StreamMessageThemeData( return StreamMessageThemeData(
messageTextStyle: messageTextStyle ?? this.messageTextStyle, messageTextStyle: messageTextStyle ?? this.messageTextStyle,
@@ -89,6 +94,7 @@ class StreamMessageThemeData with Diagnosticable {
reactionsBorderColor: reactionsBorderColor ?? this.reactionsBorderColor, reactionsBorderColor: reactionsBorderColor ?? this.reactionsBorderColor,
reactionsMaskColor: reactionsMaskColor ?? this.reactionsMaskColor, reactionsMaskColor: reactionsMaskColor ?? this.reactionsMaskColor,
linkBackgroundColor: linkBackgroundColor ?? this.linkBackgroundColor, linkBackgroundColor: linkBackgroundColor ?? this.linkBackgroundColor,
urlLinkTitleMaxLine: urlLinkTitleMaxLine ?? this.urlLinkTitleMaxLine,
); );
} }
@@ -148,6 +154,7 @@ class StreamMessageThemeData with Diagnosticable {
reactionsBorderColor: other.reactionsBorderColor, reactionsBorderColor: other.reactionsBorderColor,
reactionsMaskColor: other.reactionsMaskColor, reactionsMaskColor: other.reactionsMaskColor,
linkBackgroundColor: other.linkBackgroundColor, linkBackgroundColor: other.linkBackgroundColor,
urlLinkTitleMaxLine: other.urlLinkTitleMaxLine,
); );
} }
@@ -167,7 +174,8 @@ class StreamMessageThemeData with Diagnosticable {
reactionsBorderColor == other.reactionsBorderColor && reactionsBorderColor == other.reactionsBorderColor &&
reactionsMaskColor == other.reactionsMaskColor && reactionsMaskColor == other.reactionsMaskColor &&
avatarTheme == other.avatarTheme && avatarTheme == other.avatarTheme &&
linkBackgroundColor == other.linkBackgroundColor; linkBackgroundColor == other.linkBackgroundColor &&
urlLinkTitleMaxLine == other.urlLinkTitleMaxLine;
@override @override
int get hashCode => int get hashCode =>
@@ -182,7 +190,8 @@ class StreamMessageThemeData with Diagnosticable {
reactionsBorderColor.hashCode ^ reactionsBorderColor.hashCode ^
reactionsMaskColor.hashCode ^ reactionsMaskColor.hashCode ^
avatarTheme.hashCode ^ avatarTheme.hashCode ^
linkBackgroundColor.hashCode; linkBackgroundColor.hashCode ^
urlLinkTitleMaxLine.hashCode;
@override @override
void debugFillProperties(DiagnosticPropertiesBuilder properties) { void debugFillProperties(DiagnosticPropertiesBuilder properties) {
@@ -199,6 +208,7 @@ class StreamMessageThemeData with Diagnosticable {
..add(ColorProperty('reactionsBackgroundColor', reactionsBackgroundColor)) ..add(ColorProperty('reactionsBackgroundColor', reactionsBackgroundColor))
..add(ColorProperty('reactionsBorderColor', reactionsBorderColor)) ..add(ColorProperty('reactionsBorderColor', reactionsBorderColor))
..add(ColorProperty('reactionsMaskColor', reactionsMaskColor)) ..add(ColorProperty('reactionsMaskColor', reactionsMaskColor))
..add(ColorProperty('linkBackgroundColor', linkBackgroundColor)); ..add(ColorProperty('linkBackgroundColor', linkBackgroundColor))
..add(DiagnosticsProperty('urlLinkTitleMaxLine', urlLinkTitleMaxLine));
} }
} }