Merge pull request #241 from GetStream/nash/core-docs

Update Core Documentation
This commit is contained in:
Deven Joshi
2021-01-29 12:48:55 +05:30
committed by GitHub
5 changed files with 53 additions and 42 deletions
@@ -11,6 +11,7 @@ import 'stream_chat_core.dart';
/// [ChannelListCore] is a simplified class that allows fetching a list of channels while exposing UI builders. /// [ChannelListCore] is a simplified class that allows fetching a list of channels while exposing UI builders.
/// A [ChannelListController] is used to reload and paginate data. /// A [ChannelListController] is used to reload and paginate data.
/// ///
///
/// ```dart /// ```dart
/// class ChannelListPage extends StatelessWidget { /// class ChannelListPage extends StatelessWidget {
/// @override /// @override
@@ -50,20 +51,19 @@ import 'stream_chat_core.dart';
/// } /// }
/// ``` /// ```
/// ///
///
/// Make sure to have a [StreamChatCore] ancestor in order to provide the information about the channels. /// Make sure to have a [StreamChatCore] ancestor in order to provide the information about the channels.
class ChannelListCore extends StatefulWidget { class ChannelListCore extends StatefulWidget {
/// Instantiate a new ChannelListView /// Instantiate a new ChannelListView
ChannelListCore({ ChannelListCore({
Key key, Key key,
this.filter,
this.options,
this.sort,
this.pagination,
@required this.errorBuilder, @required this.errorBuilder,
@required this.emptyBuilder, @required this.emptyBuilder,
@required this.loadingBuilder, @required this.loadingBuilder,
@required this.listBuilder, @required this.listBuilder,
this.filter,
this.options,
this.sort,
this.pagination,
this.channelListController, this.channelListController,
}) : super(key: key); }) : super(key: key);
@@ -27,25 +27,22 @@ import 'message_search_bloc.dart';
/// } /// }
/// ``` /// ```
/// ///
///
/// Make sure to have a [MessageSearchBloc] ancestor in order to provide the information about the messages. /// 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 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 MessageSearchListCore extends StatefulWidget { class MessageSearchListCore extends StatefulWidget {
/// Instantiate a new MessageSearchListView /// Instantiate a new MessageSearchListView
const MessageSearchListCore({ const MessageSearchListCore({
Key key, Key key,
@required this.emptyBuilder,
@required this.errorBuilder,
@required this.loadingBuilder,
@required this.childBuilder,
this.messageQuery, this.messageQuery,
this.filters, this.filters,
this.sortOptions, this.sortOptions,
this.paginationParams, this.paginationParams,
this.messageFilters, this.messageFilters,
@required this.emptyBuilder,
@required this.errorBuilder,
@required this.loadingBuilder,
@required this.childBuilder,
this.messageSearchListController, this.messageSearchListController,
}) : super(key: key); }) : super(key: key);
@@ -4,8 +4,14 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:stream_chat/stream_chat.dart'; import 'package:stream_chat/stream_chat.dart';
/// Widget used to provide information about the chat to the widget tree /// Widget used to provide information about the chat to the widget tree.
/// This Widget is used to react to life cycle changes and system updates.
/// When the app goes into the background, the websocket connection is kept alive
/// for two minutes before being terminated.
/// ///
/// Conversely, when app is resumed or restarted, a new connection is initiated.
///
/// ```dart
/// class MyApp extends StatelessWidget { /// class MyApp extends StatelessWidget {
/// final Client client; /// final Client client;
/// ///
@@ -15,7 +21,7 @@ import 'package:stream_chat/stream_chat.dart';
/// Widget build(BuildContext context) { /// Widget build(BuildContext context) {
/// return MaterialApp( /// return MaterialApp(
/// home: Container( /// home: Container(
/// child: StreamChat( /// child: StreamChatCore(
/// client: client, /// client: client,
/// child: ChannelListPage(), /// child: ChannelListPage(),
/// ), /// ),
@@ -23,22 +29,25 @@ import 'package:stream_chat/stream_chat.dart';
/// ); /// );
/// } /// }
/// } /// }
/// ```
/// ///
/// Use [StreamChatCore.of] to get the current [StreamChatCoreState] instance.
class StreamChatCore extends StatefulWidget { class StreamChatCore extends StatefulWidget {
// ignore: public_member_api_docs /// Instance of Stream Chat Client containing information about the current
/// application.
final Client client; final Client client;
// ignore: public_member_api_docs
/// Widget descendant.
final Widget child; final Widget child;
// ignore: public_member_api_docs /// Constructor used for creating a new instance of [StreamChatCore].
///
/// [StreamChatCore] is a stateful widget which reacts to system events and updates
/// Stream's connection status accordingly.
StreamChatCore({ StreamChatCore({
Key key, Key key,
@required this.client, @required this.client,
@required this.child, @required this.child,
}) : super( }) : super(key: key);
key: key,
);
@override @override
StreamChatCoreState createState() => StreamChatCoreState(); StreamChatCoreState createState() => StreamChatCoreState();
@@ -58,11 +67,12 @@ class StreamChatCore extends StatefulWidget {
} }
} }
/// The current state of the StreamChat widget /// State class associated with [StreamChatCore].
class StreamChatCoreState extends State<StreamChatCore> class StreamChatCoreState extends State<StreamChatCore>
with WidgetsBindingObserver { with WidgetsBindingObserver {
// ignore: public_member_api_docs /// Initialized client used throughout the application.
Client get client => widget.client; Client get client => widget.client;
Timer _disconnectTimer; Timer _disconnectTimer;
@override @override
@@ -47,25 +47,25 @@ import 'package:stream_chat_flutter_core/src/users_bloc.dart';
/// } /// }
/// ``` /// ```
/// ///
/// [UsersBloc] must be the ancestor of this widget. This is necessary since
/// [UserListCore] depends on functionality contained within [UsersBloc].
/// ///
/// Make sure to have a [UsersBloc] ancestor in order to provide the information about the users.
/// The widget uses a [ListView.separated], [GridView.builder] to render the list, grid of channels. /// The widget uses a [ListView.separated], [GridView.builder] to render the list, grid of channels.
/// /// The parameters [listBuilder], [loadingBuilder], [emptyBuilder] and [errorBuilder] must all be supplied
/// The widget components render the ui based on the first ancestor of type [StreamChatTheme]. /// and not null.
/// Modify it to change the widget appearance.
class UserListCore extends StatefulWidget { class UserListCore extends StatefulWidget {
/// Instantiate a new UserListView /// Instantiate a new [UserListCore]
const UserListCore({ const UserListCore({
Key key, Key key,
@required this.errorBuilder,
@required this.emptyBuilder,
@required this.loadingBuilder,
@required this.listBuilder,
this.filter, this.filter,
this.options, this.options,
this.sort, this.sort,
this.pagination, this.pagination,
this.groupAlphabetically = false, this.groupAlphabetically = false,
@required this.errorBuilder,
@required this.emptyBuilder,
@required this.loadingBuilder,
@required this.listBuilder,
this.userListController, this.userListController,
}) : super(key: key); }) : super(key: key);
@@ -138,9 +138,9 @@ class _UserListCoreState extends State<UserListCore>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final usersBloc = UsersBloc.of(context); final _usersBloc = UsersBloc.of(context);
return _buildListView(usersBloc); return _buildListView(_usersBloc);
} }
bool get isListAlreadySorted => bool get isListAlreadySorted =>
@@ -207,9 +207,9 @@ class _UserListCoreState extends State<UserListCore>
} }
void loadData() { void loadData() {
final usersBloc = UsersBloc.of(context); final _usersBloc = UsersBloc.of(context);
usersBloc.queryUsers( _usersBloc.queryUsers(
filter: widget.filter, filter: widget.filter,
sort: widget.sort, sort: widget.sort,
pagination: widget.pagination, pagination: widget.pagination,
@@ -218,13 +218,13 @@ class _UserListCoreState extends State<UserListCore>
} }
void paginateData() { void paginateData() {
final usersBloc = UsersBloc.of(context); final _usersBloc = UsersBloc.of(context);
usersBloc.queryUsers( _usersBloc.queryUsers(
filter: widget.filter, filter: widget.filter,
sort: widget.sort, sort: widget.sort,
pagination: widget.pagination.copyWith( pagination: widget.pagination.copyWith(
offset: usersBloc.users?.length ?? 0, offset: _usersBloc.users?.length ?? 0,
), ),
options: widget.options, options: widget.options,
); );
@@ -249,7 +249,9 @@ class _UserListCoreState extends State<UserListCore>
} }
} }
// ignore: public_member_api_docs /// Represents an item in a the user stream list.
/// Header items are prefixed with the key `HEADER` While users are prefixed with
/// `USER`.
abstract class ListItem { abstract class ListItem {
// ignore: public_member_api_docs // ignore: public_member_api_docs
String get key { String get key {
@@ -4,7 +4,7 @@ import 'package:stream_chat/stream_chat.dart';
import 'stream_chat_core.dart'; import 'stream_chat_core.dart';
/// Widget dedicated to the management of a users list with pagination /// Widget dedicated to the management of a users list with pagination.
class UsersBloc extends StatefulWidget { class UsersBloc extends StatefulWidget {
/// The widget child /// The widget child
final Widget child; final Widget child;
@@ -49,7 +49,9 @@ class UsersBlocState extends State<UsersBloc>
/// The stream notifying the state of queryUsers call /// The stream notifying the state of queryUsers call
Stream<bool> get queryUsersLoading => _queryUsersLoadingController.stream; Stream<bool> get queryUsersLoading => _queryUsersLoadingController.stream;
/// Calls [Client.queryUsers] updating [queryUsersLoading] stream /// The Query Users method allows you to search for users and see if they are
/// online/offline.
/// [API Reference](https://getstream.io/chat/docs/flutter-dart/query_users/?language=dart)
Future<void> queryUsers({ Future<void> queryUsers({
Map<String, dynamic> filter, Map<String, dynamic> filter,
List<SortOption> sort, List<SortOption> sort,