Skip to content

Commit

Permalink
feat: change onPressUserProfile callback to use the ChatUserModel
Browse files Browse the repository at this point in the history
  • Loading branch information
freekvandeven committed May 9, 2024
1 parent 06167d2 commit 86c50f4
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Add a serviceBuilder 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,17 @@ Widget _chatDetailScreenRoute(
service: configuration.chatService,
chatId: chatId,
textfieldBottomPadding: configuration.textfieldBottomPadding ?? 0,
onPressUserProfile: (userId) async {
onPressUserProfile: (user) async {
if (configuration.onPressUserProfile != null) {
return configuration.onPressUserProfile?.call();
return configuration.onPressUserProfile?.call(context, user);
}
return Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => _chatProfileScreenRoute(
configuration,
context,
chatId,
userId,
user.id,
),
),
);
Expand Down Expand Up @@ -171,7 +171,7 @@ Widget _chatProfileScreenRoute(
userId: userId,
onTapUser: (user) async {
if (configuration.onPressUserProfile != null) {
return configuration.onPressUserProfile!.call();
return configuration.onPressUserProfile!.call(context, user);
}

return Navigator.of(context).push(
Expand Down
10 changes: 5 additions & 5 deletions packages/flutter_chat/lib/src/flutter_chat_userstory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ List<GoRoute> getChatStoryRoutes(
service: service,
chatId: chatId!,
textfieldBottomPadding: configuration.textfieldBottomPadding ?? 0,
onPressUserProfile: (userId) async {
onPressUserProfile: (user) async {
if (configuration.onPressUserProfile != null) {
return configuration.onPressUserProfile?.call();
return configuration.onPressUserProfile?.call(context, user);
}
return context.push(
ChatUserStoryRoutes.chatProfileScreenPath(chatId, userId),
ChatUserStoryRoutes.chatProfileScreenPath(chatId, user.id),
);
},
onMessageSubmit: (message) async {
Expand Down Expand Up @@ -257,11 +257,11 @@ List<GoRoute> getChatStoryRoutes(
userId: id,
onTapUser: (user) async {
if (configuration.onPressUserProfile != null) {
return configuration.onPressUserProfile!.call();
return configuration.onPressUserProfile!.call(context, user);
}

return context.push(
ChatUserStoryRoutes.chatProfileScreenPath(chatId, user),
ChatUserStoryRoutes.chatProfileScreenPath(chatId, user.id),
);
},
);
Expand Down
12 changes: 11 additions & 1 deletion packages/flutter_chat/lib/src/models/chat_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ class ChatUserStoryConfiguration {

/// Builder for chat options based on context.
final Function(List<ChatUserModel>, String)? onPressCompleteGroupChatCreation;

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;

/// If true, the user will be routed to the new chat screen if there are
Expand All @@ -108,11 +111,18 @@ class ChatUserStoryConfiguration {
final Function()? onPressStartChat;

/// Callback function triggered when user profile is pressed.
final Function()? onPressUserProfile;
final Function(BuildContext context, ChatUserModel user)? onPressUserProfile;

final double? textfieldBottomPadding;

final Color? iconDisabledColor;

/// The text style used for the unread message counter.
final TextStyle? unreadMessageTextStyle;

final Widget? Function(BuildContext context)? loadingWidgetBuilder;

final Widget Function(String userFullName)? usernameBuilder;

final Widget Function(String chatTitle)? chatTitleBuilder;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ChatDetailRow extends StatefulWidget {

/// The previous chat message model.
final ChatMessageModel? previousMessage;
final Function(String? userId) onPressUserProfile;
final Function(ChatUserModel user) onPressUserProfile;
final Widget Function(String userFullName)? usernameBuilder;

/// Flag indicating whether to show the time.
Expand Down Expand Up @@ -65,7 +65,7 @@ class _ChatDetailRowState extends State<ChatDetailRow> {
if (isNewDate || isSameSender) ...[
GestureDetector(
onTap: () => widget.onPressUserProfile(
widget.message.sender.id,
widget.message.sender,
),
child: Padding(
padding: const EdgeInsets.only(left: 10.0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ChatDetailScreen extends StatefulWidget {
final int pageSize;
final double textfieldBottomPadding;
final Color? iconDisabledColor;
final Function(String? userId) onPressUserProfile;
final Function(ChatUserModel user) onPressUserProfile;
// ignore: avoid_positional_boolean_parameters
final Widget? Function(BuildContext context)? loadingWidgetBuilder;
final Widget Function(String userFullName)? usernameBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ChatProfileScreen extends StatefulWidget {
final String? userId;

/// Callback function for tapping on a user.
final Function(String userId) onTapUser;
final Function(ChatUserModel user) onTapUser;

@override
State<ChatProfileScreen> createState() => _ProfileScreenState();
Expand Down Expand Up @@ -124,7 +124,7 @@ class _ProfileScreenState extends State<ChatProfileScreen> {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0),
child: GestureDetector(
onTap: () => widget.onTapUser.call(e.id!),
onTap: () => widget.onTapUser.call(e),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
Expand Down

0 comments on commit 86c50f4

Please sign in to comment.