mirror of
https://github.com/Iconica-Development/flutter_chat.git
synced 2025-05-18 18:33:49 +02:00
fix: allow the messageTheme to override default behavior for message time
This commit is contained in:
parent
590a339d0d
commit
11d8c81161
2 changed files with 19 additions and 5 deletions
|
@ -124,9 +124,10 @@ class MessageTheme {
|
||||||
this.textAlignment,
|
this.textAlignment,
|
||||||
this.showName,
|
this.showName,
|
||||||
this.showTime,
|
this.showTime,
|
||||||
|
this.showFullDate,
|
||||||
});
|
});
|
||||||
|
|
||||||
///
|
/// Creates a [MessageTheme] from a [ThemeData]
|
||||||
factory MessageTheme.fromTheme(ThemeData theme) => MessageTheme(
|
factory MessageTheme.fromTheme(ThemeData theme) => MessageTheme(
|
||||||
backgroundColor: theme.colorScheme.primary,
|
backgroundColor: theme.colorScheme.primary,
|
||||||
nameColor: theme.colorScheme.onPrimary,
|
nameColor: theme.colorScheme.onPrimary,
|
||||||
|
@ -137,8 +138,9 @@ class MessageTheme {
|
||||||
textAlignment: TextAlign.start,
|
textAlignment: TextAlign.start,
|
||||||
messageSidePadding: 144.0,
|
messageSidePadding: 144.0,
|
||||||
messageAlignment: null,
|
messageAlignment: null,
|
||||||
showName: true,
|
showName: null,
|
||||||
showTime: true,
|
showTime: true,
|
||||||
|
showFullDate: null,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// The alignment of the message in the chat
|
/// The alignment of the message in the chat
|
||||||
|
@ -179,13 +181,20 @@ class MessageTheme {
|
||||||
final double? messageSidePadding;
|
final double? messageSidePadding;
|
||||||
|
|
||||||
/// If the name of the sender should be shown above the message
|
/// If the name of the sender should be shown above the message
|
||||||
/// Defaults to true
|
/// If not set the name will be shown if the previous message was not from the
|
||||||
|
/// same sender.
|
||||||
final bool? showName;
|
final bool? showName;
|
||||||
|
|
||||||
/// If the time of the message should be shown below the message
|
/// If the time of the message should be shown below the message
|
||||||
/// Defaults to true
|
/// Defaults to true
|
||||||
final bool? showTime;
|
final bool? showTime;
|
||||||
|
|
||||||
|
/// If the full date should be shown with the time in the message
|
||||||
|
/// If not set the date will be shown if the previous message was not on the
|
||||||
|
/// same day.
|
||||||
|
/// If [showTime] is false, this value is ignored.
|
||||||
|
final bool? showFullDate;
|
||||||
|
|
||||||
/// Creates a copy of the current object with the provided values
|
/// Creates a copy of the current object with the provided values
|
||||||
MessageTheme copyWith({
|
MessageTheme copyWith({
|
||||||
Color? backgroundColor,
|
Color? backgroundColor,
|
||||||
|
@ -199,6 +208,7 @@ class MessageTheme {
|
||||||
TextAlign? textAlignment,
|
TextAlign? textAlignment,
|
||||||
bool? showName,
|
bool? showName,
|
||||||
bool? showTime,
|
bool? showTime,
|
||||||
|
bool? showFullDate,
|
||||||
}) =>
|
}) =>
|
||||||
MessageTheme(
|
MessageTheme(
|
||||||
backgroundColor: backgroundColor ?? this.backgroundColor,
|
backgroundColor: backgroundColor ?? this.backgroundColor,
|
||||||
|
@ -212,6 +222,7 @@ class MessageTheme {
|
||||||
textAlignment: textAlignment ?? this.textAlignment,
|
textAlignment: textAlignment ?? this.textAlignment,
|
||||||
showName: showName ?? this.showName,
|
showName: showName ?? this.showName,
|
||||||
showTime: showTime ?? this.showTime,
|
showTime: showTime ?? this.showTime,
|
||||||
|
showFullDate: showFullDate ?? this.showFullDate,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// If a value is null in the first object, the value from the second object
|
/// If a value is null in the first object, the value from the second object
|
||||||
|
@ -228,6 +239,7 @@ class MessageTheme {
|
||||||
textAlignment: textAlignment ?? other.textAlignment,
|
textAlignment: textAlignment ?? other.textAlignment,
|
||||||
showName: showName ?? other.showName,
|
showName: showName ?? other.showName,
|
||||||
showTime: showTime ?? other.showTime,
|
showTime: showTime ?? other.showTime,
|
||||||
|
showFullDate: showFullDate ?? other.showFullDate,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -144,9 +144,11 @@ class _ChatMessageBubble extends StatelessWidget {
|
||||||
var isNewDate = previousMessage != null &&
|
var isNewDate = previousMessage != null &&
|
||||||
message.timestamp.day != previousMessage?.timestamp.day;
|
message.timestamp.day != previousMessage?.timestamp.day;
|
||||||
|
|
||||||
|
var showFullDateOnMessage =
|
||||||
|
messageTheme.showFullDate ?? (isNewDate || previousMessage == null);
|
||||||
var messageTime = dateFormatter.format(
|
var messageTime = dateFormatter.format(
|
||||||
date: message.timestamp,
|
date: message.timestamp,
|
||||||
showFullDate: isNewDate || previousMessage == null,
|
showFullDate: showFullDateOnMessage,
|
||||||
);
|
);
|
||||||
|
|
||||||
var senderTitle =
|
var senderTitle =
|
||||||
|
@ -176,7 +178,7 @@ class _ChatMessageBubble extends StatelessWidget {
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
if (messageTheme.showName! && !isSameSender) ...[
|
if (messageTheme.showName ?? !isSameSender) ...[
|
||||||
SizedBox(height: options.spacing.chatBetweenMessagesPadding),
|
SizedBox(height: options.spacing.chatBetweenMessagesPadding),
|
||||||
senderTitleText,
|
senderTitleText,
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in a new issue