feat: add service and translationbuilder for userstory configuration to fetch both when needed

This commit is contained in:
Freek van de Ven 2024-05-09 19:09:22 +02:00
parent 37e975ceec
commit 06167d202e
9 changed files with 54 additions and 25 deletions

View file

@ -1,3 +1,8 @@
## 2.0.0
- Add a serviceBuilder to the userstory configuration
- Add a translationsBuilder to the userstory configuration
## 1.4.3
- Added default styling.

View file

@ -4,7 +4,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_chat/flutter_chat.dart';
import 'package:uuid/uuid.dart';
/// Navigates to the chat user story screen.
///

View file

@ -14,9 +14,11 @@ List<GoRoute> getChatStoryRoutes(
GoRoute(
path: ChatUserStoryRoutes.chatScreen,
pageBuilder: (context, state) {
var service = configuration.chatServiceBuilder?.call(context) ??
configuration.chatService;
var chatScreen = ChatScreen(
unreadMessageTextStyle: configuration.unreadMessageTextStyle,
service: configuration.chatService,
service: service,
options: configuration.chatOptionsBuilder(context),
onNoChats: () async =>
context.push(ChatUserStoryRoutes.newChatScreen),
@ -34,7 +36,8 @@ List<GoRoute> getChatStoryRoutes(
configuration.onDeleteChat?.call(context, chat) ??
configuration.chatService.chatOverviewService.deleteChat(chat),
deleteChatDialog: configuration.deleteChatDialog,
translations: configuration.translations,
translations: configuration.translationsBuilder?.call(context) ??
configuration.translations,
);
return buildScreenWithoutTransition(
context: context,
@ -53,6 +56,8 @@ List<GoRoute> getChatStoryRoutes(
path: ChatUserStoryRoutes.chatDetailScreen,
pageBuilder: (context, state) {
var chatId = state.pathParameters['id'];
var service = configuration.chatServiceBuilder?.call(context) ??
configuration.chatService;
var chatDetailScreen = ChatDetailScreen(
chatTitleBuilder: configuration.chatTitleBuilder,
usernameBuilder: configuration.usernameBuilder,
@ -60,8 +65,9 @@ List<GoRoute> getChatStoryRoutes(
iconDisabledColor: configuration.iconDisabledColor,
pageSize: configuration.messagePageSize,
options: configuration.chatOptionsBuilder(context),
translations: configuration.translations,
service: configuration.chatService,
translations: configuration.translationsBuilder?.call(context) ??
configuration.translations,
service: service,
chatId: chatId!,
textfieldBottomPadding: configuration.textfieldBottomPadding ?? 0,
onPressUserProfile: (userId) async {
@ -120,10 +126,13 @@ List<GoRoute> getChatStoryRoutes(
GoRoute(
path: ChatUserStoryRoutes.newChatScreen,
pageBuilder: (context, state) {
var service = configuration.chatServiceBuilder?.call(context) ??
configuration.chatService;
var newChatScreen = NewChatScreen(
options: configuration.chatOptionsBuilder(context),
translations: configuration.translations,
service: configuration.chatService,
translations: configuration.translationsBuilder?.call(context) ??
configuration.translations,
service: service,
onPressCreateChat: (user) async {
configuration.onPressCreateChat?.call(user);
if (configuration.onPressCreateChat != null) return;
@ -163,10 +172,13 @@ List<GoRoute> getChatStoryRoutes(
GoRoute(
path: ChatUserStoryRoutes.newGroupChatScreen,
pageBuilder: (context, state) {
var service = configuration.chatServiceBuilder?.call(context) ??
configuration.chatService;
var newGroupChatScreen = NewGroupChatScreen(
options: configuration.chatOptionsBuilder(context),
translations: configuration.translations,
service: configuration.chatService,
translations: configuration.translationsBuilder?.call(context) ??
configuration.translations,
service: service,
onPressGroupChatOverview: (users) async => context.push(
ChatUserStoryRoutes.newGroupChatOverviewScreen,
extra: users,
@ -188,11 +200,14 @@ List<GoRoute> getChatStoryRoutes(
GoRoute(
path: ChatUserStoryRoutes.newGroupChatOverviewScreen,
pageBuilder: (context, state) {
var service = configuration.chatServiceBuilder?.call(context) ??
configuration.chatService;
var users = state.extra! as List<ChatUserModel>;
var newGroupChatOverviewScreen = NewGroupChatOverviewScreen(
options: configuration.chatOptionsBuilder(context),
translations: configuration.translations,
service: configuration.chatService,
translations: configuration.translationsBuilder?.call(context) ??
configuration.translations,
service: service,
users: users,
onPressCompleteGroupChatCreation: (users, groupChatName) async {
configuration.onPressCompleteGroupChatCreation
@ -232,9 +247,12 @@ List<GoRoute> getChatStoryRoutes(
var chatId = state.pathParameters['id'];
var userId = state.pathParameters['userId'];
var id = userId == 'null' ? null : userId;
var service = configuration.chatServiceBuilder?.call(context) ??
configuration.chatService;
var profileScreen = ChatProfileScreen(
translations: configuration.translations,
chatService: configuration.chatService,
translations: configuration.translationsBuilder?.call(context) ??
configuration.translations,
chatService: service,
chatId: chatId!,
userId: id,
onTapUser: (user) async {

View file

@ -14,6 +14,7 @@ class ChatUserStoryConfiguration {
const ChatUserStoryConfiguration({
required this.chatService,
required this.chatOptionsBuilder,
this.chatServiceBuilder,
this.onPressStartChat,
this.onPressChat,
this.onDeleteChat,
@ -28,6 +29,7 @@ class ChatUserStoryConfiguration {
this.disableDismissForPermanentChats = false,
this.routeToNewChatIfEmpty = true,
this.translations = const ChatTranslations(),
this.translationsBuilder,
this.chatPageBuilder,
this.onPressChatTitle,
this.afterMessageSent,
@ -44,6 +46,9 @@ class ChatUserStoryConfiguration {
/// The service responsible for handling chat-related functionalities.
final ChatService chatService;
/// A method to get the chat service only when needed and with a context.
final ChatService Function(BuildContext context)? chatServiceBuilder;
/// Callback function triggered when a chat is pressed.
final Function(BuildContext, ChatModel)? onPressChat;
@ -53,6 +58,9 @@ class ChatUserStoryConfiguration {
/// Translations for internationalization/localization support.
final ChatTranslations translations;
/// Translations builder because context might be needed for translations.
final ChatTranslations Function(BuildContext context)? translationsBuilder;
/// Determines whether dismissing is disabled for permanent chats.
final bool disableDismissForPermanentChats;

View file

@ -4,7 +4,7 @@
name: flutter_chat
description: A new Flutter package project.
version: 1.4.3
version: 2.0.0
publish_to: none
@ -20,17 +20,17 @@ dependencies:
git:
url: https://github.com/Iconica-Development/flutter_chat
path: packages/flutter_chat_view
ref: 1.4.3
ref: 2.0.0
flutter_chat_interface:
git:
url: https://github.com/Iconica-Development/flutter_chat
path: packages/flutter_chat_interface
ref: 1.4.3
ref: 2.0.0
flutter_chat_local:
git:
url: https://github.com/Iconica-Development/flutter_chat
path: packages/flutter_chat_local
ref: 1.4.3
ref: 2.0.0
uuid: ^4.3.3
dev_dependencies:

View file

@ -4,7 +4,7 @@
name: flutter_chat_firebase
description: A new Flutter package project.
version: 1.4.3
version: 2.0.0
publish_to: none
environment:
@ -23,7 +23,7 @@ dependencies:
git:
url: https://github.com/Iconica-Development/flutter_chat
path: packages/flutter_chat_interface
ref: 1.4.3
ref: 2.0.0
dev_dependencies:
flutter_iconica_analysis:

View file

@ -4,7 +4,7 @@
name: flutter_chat_interface
description: A new Flutter package project.
version: 1.4.3
version: 2.0.0
publish_to: none
environment:

View file

@ -1,8 +1,7 @@
name: flutter_chat_local
description: "A new Flutter package project."
version: 1.4.3
version: 2.0.0
publish_to: none
homepage:
environment:
sdk: ">=3.2.5 <4.0.0"
@ -15,7 +14,7 @@ dependencies:
git:
url: https://github.com/Iconica-Development/flutter_chat
path: packages/flutter_chat_interface
ref: 1.4.3
ref: 2.0.0
dev_dependencies:
flutter_test:

View file

@ -4,7 +4,7 @@
name: flutter_chat_view
description: A standard flutter package.
version: 1.4.3
version: 2.0.0
publish_to: none
@ -20,7 +20,7 @@ dependencies:
git:
url: https://github.com/Iconica-Development/flutter_chat
path: packages/flutter_chat_interface
ref: 1.4.3
ref: 2.0.0
cached_network_image: ^3.2.2
flutter_image_picker:
git: