mirror of
https://github.com/Iconica-Development/flutter_chat.git
synced 2025-05-19 10:53:51 +02:00
feat: add chatTitleResolver to ChatOptions to override chatTitle behavior
This commit is contained in:
parent
281188c2b7
commit
990a89199b
2 changed files with 11 additions and 8 deletions
|
@ -16,6 +16,7 @@ class ChatOptions {
|
||||||
this.spacing = const ChatSpacing(),
|
this.spacing = const ChatSpacing(),
|
||||||
this.messageTheme,
|
this.messageTheme,
|
||||||
this.messageThemeResolver = _defaultMessageThemeResolver,
|
this.messageThemeResolver = _defaultMessageThemeResolver,
|
||||||
|
this.chatTitleResolver,
|
||||||
this.iconEnabledColor,
|
this.iconEnabledColor,
|
||||||
this.iconDisabledColor,
|
this.iconDisabledColor,
|
||||||
this.chatAlignment,
|
this.chatAlignment,
|
||||||
|
@ -64,6 +65,10 @@ class ChatOptions {
|
||||||
/// the [messageTheme] will be used.
|
/// the [messageTheme] will be used.
|
||||||
final MessageThemeResolver messageThemeResolver;
|
final MessageThemeResolver messageThemeResolver;
|
||||||
|
|
||||||
|
/// If [chatTitleResolver] is set, it will be used to get the title of
|
||||||
|
/// the chat in the ChatDetailScreen.
|
||||||
|
final ChatTitleResolver? chatTitleResolver;
|
||||||
|
|
||||||
/// The alignment of the chatmessages in the ChatDetailScreen.
|
/// The alignment of the chatmessages in the ChatDetailScreen.
|
||||||
/// Defaults to [Alignment.bottomCenter]
|
/// Defaults to [Alignment.bottomCenter]
|
||||||
final Alignment? chatAlignment;
|
final Alignment? chatAlignment;
|
||||||
|
@ -81,6 +86,10 @@ class ChatOptions {
|
||||||
final int pageSize;
|
final int pageSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Typedef for the chatTitleResolver function that is used to get a title for
|
||||||
|
/// a chat.
|
||||||
|
typedef ChatTitleResolver = String Function(ChatModel chat);
|
||||||
|
|
||||||
/// Typedef for the messageThemeResolver function that is used to get a
|
/// Typedef for the messageThemeResolver function that is used to get a
|
||||||
/// [MessageTheme] for a message. This can return null so you can fall back to
|
/// [MessageTheme] for a message. This can return null so you can fall back to
|
||||||
/// default values for some messages.
|
/// default values for some messages.
|
||||||
|
|
|
@ -21,7 +21,6 @@ class ChatDetailScreen extends HookWidget {
|
||||||
required this.onUploadImage,
|
required this.onUploadImage,
|
||||||
required this.onMessageSubmit,
|
required this.onMessageSubmit,
|
||||||
required this.onReadChat,
|
required this.onReadChat,
|
||||||
this.getChatTitle,
|
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -44,9 +43,6 @@ class ChatDetailScreen extends HookWidget {
|
||||||
/// Callback function triggered when the chat is read.
|
/// Callback function triggered when the chat is read.
|
||||||
final Function(ChatModel chat) onReadChat;
|
final Function(ChatModel chat) onReadChat;
|
||||||
|
|
||||||
/// Callback function to get the chat title
|
|
||||||
final String Function(ChatModel chat)? getChatTitle;
|
|
||||||
|
|
||||||
/// Callback for when the user wants to navigate back
|
/// Callback for when the user wants to navigate back
|
||||||
final VoidCallback? onExit;
|
final VoidCallback? onExit;
|
||||||
|
|
||||||
|
@ -74,7 +70,6 @@ class ChatDetailScreen extends HookWidget {
|
||||||
_computeChatTitle(
|
_computeChatTitle(
|
||||||
chatScope: chatScope,
|
chatScope: chatScope,
|
||||||
chat: chat,
|
chat: chat,
|
||||||
getChatTitle: getChatTitle,
|
|
||||||
onTitleComputed: (title) => chatTitle.value = title,
|
onTitleComputed: (title) => chatTitle.value = title,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -128,11 +123,10 @@ class ChatDetailScreen extends HookWidget {
|
||||||
Future<void> _computeChatTitle({
|
Future<void> _computeChatTitle({
|
||||||
required ChatScope chatScope,
|
required ChatScope chatScope,
|
||||||
required ChatModel chat,
|
required ChatModel chat,
|
||||||
required String? Function(ChatModel chat)? getChatTitle,
|
|
||||||
required void Function(String?) onTitleComputed,
|
required void Function(String?) onTitleComputed,
|
||||||
}) async {
|
}) async {
|
||||||
if (getChatTitle != null) {
|
if (chatScope.options.chatTitleResolver != null) {
|
||||||
onTitleComputed(getChatTitle(chat));
|
onTitleComputed(chatScope.options.chatTitleResolver!.call(chat));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue