Merge pull request #1210 from GetStream/docs/fix-user-list-view-doc

docs(doc): fix user list view doc
This commit is contained in:
Salvatore Giordano
2022-06-16 09:56:23 +02:00
committed by GitHub
@@ -24,26 +24,22 @@ Make sure to check the [StreamUserListController](./stream_user_list_controller.
```dart ```dart
class UserListPage extends StatefulWidget { class UserListPage extends StatefulWidget {
const UserListPage({ const UserListPage({Key? key}) : super(key: key);
Key? key,
required this.client,
}) : super(key: key);
final StreamChatClient client;
@override @override
State<UserListPage> createState() => _UserListPageState(); State<UserListPage> createState() => _UserListPageState();
} }
class _UserListPageState extends State<UserListPage> { class _UserListPageState extends State<UserListPage> {
late final _controller = StreamUserListController( late final StreamUserListController _userListController =
client: widget.client, StreamUserListController(
client: StreamChat.of(context).client,
limit: 25, limit: 25,
filter: Filter.and([ filter: Filter.and(
Filter.notEqual('id', StreamChat.of(context).currentUser!.id), [Filter.notEqual('id', StreamChat.of(context).currentUser!.id)],
]), ),
sort: [ sort: [
SortOption( const SortOption(
'name', 'name',
direction: 1, direction: 1,
), ),
@@ -51,29 +47,14 @@ class _UserListPageState extends State<UserListPage> {
); );
@override @override
void dispose() { Widget build(BuildContext context) {
_controller.dispose(); return RefreshIndicator(
super.dispose(); onRefresh: () => _userListController.refresh(),
child: StreamUserListView(
controller: _userListController,
),
);
} }
@override
Widget build(BuildContext context) => Scaffold(
body: RefreshIndicator(
onRefresh: _controller.refresh,
child: StreamChannelListView(
controller: _controller,
onChannelTap: (channel) => Navigator.push(
context,
MaterialPageRoute(
builder: (_) => StreamChannel(
channel: channel,
child: const ChannelPage(),
),
),
),
),
),
);
} }
``` ```
@@ -89,3 +70,25 @@ StreamUsersListView(
}, },
), ),
``` ```
### Selecting Users
The `StreamUserListView` widget allows selecting users in a list. The `defaultWidget` returned can be customized to indicate that it has been selected.
```dart
Set<User> _selectedUsers = {};
StreamUserListView(
controller: _userListController,
itemBuilder: (context, users, index, defaultWidget) {
return defaultWidget.copyWith(
selected: _selectedUsers.contains(users[index]),
);
},
onUserTap: (user) {
setState(() {
_selectedUsers.add(user);
});
},
);
```