feat: change onPressUserProfile callback to use the ChatUserModel

This commit is contained in:
Freek van de Ven 2024-05-09 19:46:31 +02:00
parent 06167d202e
commit 86c50f47f6
7 changed files with 26 additions and 15 deletions

View file

@ -2,6 +2,7 @@
- Add a serviceBuilder to the userstory configuration - Add a serviceBuilder to the userstory configuration
- Add a translationsBuilder to the userstory configuration - Add a translationsBuilder to the userstory configuration
- Change onPressUserProfile callback to use a ChatUserModel instead of a String
## 1.4.3 ## 1.4.3

View file

@ -95,9 +95,9 @@ Widget _chatDetailScreenRoute(
service: configuration.chatService, service: configuration.chatService,
chatId: chatId, chatId: chatId,
textfieldBottomPadding: configuration.textfieldBottomPadding ?? 0, textfieldBottomPadding: configuration.textfieldBottomPadding ?? 0,
onPressUserProfile: (userId) async { onPressUserProfile: (user) async {
if (configuration.onPressUserProfile != null) { if (configuration.onPressUserProfile != null) {
return configuration.onPressUserProfile?.call(); return configuration.onPressUserProfile?.call(context, user);
} }
return Navigator.of(context).push( return Navigator.of(context).push(
MaterialPageRoute( MaterialPageRoute(
@ -105,7 +105,7 @@ Widget _chatDetailScreenRoute(
configuration, configuration,
context, context,
chatId, chatId,
userId, user.id,
), ),
), ),
); );
@ -171,7 +171,7 @@ Widget _chatProfileScreenRoute(
userId: userId, userId: userId,
onTapUser: (user) async { onTapUser: (user) async {
if (configuration.onPressUserProfile != null) { if (configuration.onPressUserProfile != null) {
return configuration.onPressUserProfile!.call(); return configuration.onPressUserProfile!.call(context, user);
} }
return Navigator.of(context).push( return Navigator.of(context).push(

View file

@ -70,12 +70,12 @@ List<GoRoute> getChatStoryRoutes(
service: service, service: service,
chatId: chatId!, chatId: chatId!,
textfieldBottomPadding: configuration.textfieldBottomPadding ?? 0, textfieldBottomPadding: configuration.textfieldBottomPadding ?? 0,
onPressUserProfile: (userId) async { onPressUserProfile: (user) async {
if (configuration.onPressUserProfile != null) { if (configuration.onPressUserProfile != null) {
return configuration.onPressUserProfile?.call(); return configuration.onPressUserProfile?.call(context, user);
} }
return context.push( return context.push(
ChatUserStoryRoutes.chatProfileScreenPath(chatId, userId), ChatUserStoryRoutes.chatProfileScreenPath(chatId, user.id),
); );
}, },
onMessageSubmit: (message) async { onMessageSubmit: (message) async {
@ -257,11 +257,11 @@ List<GoRoute> getChatStoryRoutes(
userId: id, userId: id,
onTapUser: (user) async { onTapUser: (user) async {
if (configuration.onPressUserProfile != null) { if (configuration.onPressUserProfile != null) {
return configuration.onPressUserProfile!.call(); return configuration.onPressUserProfile!.call(context, user);
} }
return context.push( return context.push(
ChatUserStoryRoutes.chatProfileScreenPath(chatId, user), ChatUserStoryRoutes.chatProfileScreenPath(chatId, user.id),
); );
}, },
); );

View file

@ -82,7 +82,10 @@ class ChatUserStoryConfiguration {
/// Builder for chat options based on context. /// Builder for chat options based on context.
final Function(List<ChatUserModel>, String)? onPressCompleteGroupChatCreation; final Function(List<ChatUserModel>, String)? onPressCompleteGroupChatCreation;
final Function()? onPressCreateGroupChat; final Function()? onPressCreateGroupChat;
/// Builder for the chat options which can be used to style the UI of the chat
final ChatOptions Function(BuildContext context) chatOptionsBuilder; final ChatOptions Function(BuildContext context) chatOptionsBuilder;
/// If true, the user will be routed to the new chat screen if there are /// If true, the user will be routed to the new chat screen if there are
@ -108,11 +111,18 @@ class ChatUserStoryConfiguration {
final Function()? onPressStartChat; final Function()? onPressStartChat;
/// Callback function triggered when user profile is pressed. /// Callback function triggered when user profile is pressed.
final Function()? onPressUserProfile; final Function(BuildContext context, ChatUserModel user)? onPressUserProfile;
final double? textfieldBottomPadding; final double? textfieldBottomPadding;
final Color? iconDisabledColor; final Color? iconDisabledColor;
/// The text style used for the unread message counter.
final TextStyle? unreadMessageTextStyle; final TextStyle? unreadMessageTextStyle;
final Widget? Function(BuildContext context)? loadingWidgetBuilder; final Widget? Function(BuildContext context)? loadingWidgetBuilder;
final Widget Function(String userFullName)? usernameBuilder; final Widget Function(String userFullName)? usernameBuilder;
final Widget Function(String chatTitle)? chatTitleBuilder; final Widget Function(String chatTitle)? chatTitleBuilder;
} }

View file

@ -31,7 +31,7 @@ class ChatDetailRow extends StatefulWidget {
/// The previous chat message model. /// The previous chat message model.
final ChatMessageModel? previousMessage; final ChatMessageModel? previousMessage;
final Function(String? userId) onPressUserProfile; final Function(ChatUserModel user) onPressUserProfile;
final Widget Function(String userFullName)? usernameBuilder; final Widget Function(String userFullName)? usernameBuilder;
/// Flag indicating whether to show the time. /// Flag indicating whether to show the time.
@ -65,7 +65,7 @@ class _ChatDetailRowState extends State<ChatDetailRow> {
if (isNewDate || isSameSender) ...[ if (isNewDate || isSameSender) ...[
GestureDetector( GestureDetector(
onTap: () => widget.onPressUserProfile( onTap: () => widget.onPressUserProfile(
widget.message.sender.id, widget.message.sender,
), ),
child: Padding( child: Padding(
padding: const EdgeInsets.only(left: 10.0), padding: const EdgeInsets.only(left: 10.0),

View file

@ -53,7 +53,7 @@ class ChatDetailScreen extends StatefulWidget {
final int pageSize; final int pageSize;
final double textfieldBottomPadding; final double textfieldBottomPadding;
final Color? iconDisabledColor; final Color? iconDisabledColor;
final Function(String? userId) onPressUserProfile; final Function(ChatUserModel user) onPressUserProfile;
// ignore: avoid_positional_boolean_parameters // ignore: avoid_positional_boolean_parameters
final Widget? Function(BuildContext context)? loadingWidgetBuilder; final Widget? Function(BuildContext context)? loadingWidgetBuilder;
final Widget Function(String userFullName)? usernameBuilder; final Widget Function(String userFullName)? usernameBuilder;

View file

@ -26,7 +26,7 @@ class ChatProfileScreen extends StatefulWidget {
final String? userId; final String? userId;
/// Callback function for tapping on a user. /// Callback function for tapping on a user.
final Function(String userId) onTapUser; final Function(ChatUserModel user) onTapUser;
@override @override
State<ChatProfileScreen> createState() => _ProfileScreenState(); State<ChatProfileScreen> createState() => _ProfileScreenState();
@ -124,7 +124,7 @@ class _ProfileScreenState extends State<ChatProfileScreen> {
return Padding( return Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0), padding: const EdgeInsets.symmetric(vertical: 4.0),
child: GestureDetector( child: GestureDetector(
onTap: () => widget.onTapUser.call(e.id!), onTap: () => widget.onTapUser.call(e),
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,