diff --git a/lib/src/message_search_item.dart b/lib/src/message_search_item.dart index d97db708..a89f2ee0 100644 --- a/lib/src/message_search_item.dart +++ b/lib/src/message_search_item.dart @@ -3,22 +3,40 @@ import 'package:jiffy/jiffy.dart'; import 'package:stream_chat/stream_chat.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; +/// It shows the current [Message] preview. +/// +/// Usually you don't use this widget as it's the default item used by [MessageSearchListView]. +/// +/// The widget renders the ui based on the first ancestor of type [StreamChatTheme]. +/// Modify it to change the widget appearance. class MessageSearchItem extends StatelessWidget { - final Message message; - + /// Instantiate a new MessageSearchItem const MessageSearchItem({ Key key, @required this.message, + this.onTap, + this.showOnlineStatus = true, }) : super(key: key); + /// [Message] displayed + final Message message; + + /// Function called when tapping this widget + final VoidCallback onTap; + + /// If true the [MessageSearchItem] will show the current online Status + final bool showOnlineStatus; + @override Widget build(BuildContext context) { final data = Message.fromJson(message.extraData['message']); final user = data.user; debugPrint(message.toJson().toString()); return ListTile( + onTap: onTap, leading: UserAvatar( user: user, + showOnlineStatus: showOnlineStatus, constraints: BoxConstraints.tightFor( height: 40, width: 40, @@ -31,6 +49,7 @@ class MessageSearchItem extends StatelessWidget { subtitle: Row( children: [ Expanded(child: _buildSubtitle(context, data)), + SizedBox(width: 16), _buildDate(context, data), ], ), diff --git a/lib/src/message_search_list_view.dart b/lib/src/message_search_list_view.dart index f317a677..9ad013db 100644 --- a/lib/src/message_search_list_view.dart +++ b/lib/src/message_search_list_view.dart @@ -7,22 +7,36 @@ import 'package:stream_chat_flutter/src/message_search_item.dart'; import 'lazy_load_scroll_view.dart'; import 'message_search_bloc.dart'; +/// +/// It shows the list of searched messages. +/// +/// ```dart +/// class MessageSearchPage extends StatelessWidget { +/// @override +/// Widget build(BuildContext context) { +/// return Scaffold( +/// body: MessageSearchListView( +/// messageQuery: _channelQuery, +/// filters: { +/// 'members': { +/// r'$in': [user.id] +/// } +/// }, +/// paginationParams: PaginationParams(limit: 20), +/// ), +/// ); +/// } +/// } +/// ``` +/// +/// +/// Make sure to have a [MessageSearchBloc] ancestor in order to provide the information about the messages. +/// The widget uses a [ListView.separated] to render the list of messages. +/// +/// The widget components render the ui based on the first ancestor of type [StreamChatTheme]. +/// Modify it to change the widget appearance. class MessageSearchListView extends StatefulWidget { - final String messageQuery; - final Map filters; - final List sortOptions; - final PaginationParams paginationParams; - final bool pullToRefresh; - - /// The builder used when the channel list is empty. - final WidgetBuilder emptyBuilder; - - /// The builder that will be used in case of error - final Widget Function(Error error) errorBuilder; - - /// Builder used to create a custom item separator - final IndexedWidgetBuilder separatorBuilder; - + /// Instantiate a new MessageSearchListView const MessageSearchListView({ Key key, @required this.messageQuery, @@ -35,6 +49,38 @@ class MessageSearchListView extends StatefulWidget { this.pullToRefresh = true, }) : super(key: key); + /// Message String to search on + final String messageQuery; + + /// The query filters to use. + /// You can query on any of the custom fields you've defined on the [Channel]. + /// You can also filter other built-in channel fields. + final Map filters; + + /// The sorting used for the channels matching the filters. + /// Sorting is based on field and direction, multiple sorting options can be provided. + /// You can sort based on last_updated, last_message_at, updated_at, created_at or member_count. + /// Direction can be ascending or descending. + final List sortOptions; + + /// Pagination parameters + /// limit: the number of users to return (max is 30) + /// offset: the offset (max is 1000) + /// message_limit: how many messages should be included to each channel + final PaginationParams paginationParams; + + /// Set it to false to disable the pull-to-refresh widget + final bool pullToRefresh; + + /// The builder used when the channel list is empty. + final WidgetBuilder emptyBuilder; + + /// The builder that will be used in case of error + final Widget Function(Error error) errorBuilder; + + /// Builder used to create a custom item separator + final IndexedWidgetBuilder separatorBuilder; + @override _MessageSearchListViewState createState() => _MessageSearchListViewState(); }