From 9b36c2348ebbd65374c4a49d561609a7045ef70b Mon Sep 17 00:00:00 2001 From: xsahil03x Date: Wed, 18 Nov 2020 00:09:07 +0530 Subject: [PATCH] feat: add selection property to user list item --- lib/src/user_item.dart | 27 ++++++++++++++++++++------- lib/src/user_list_view.dart | 6 ++++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/lib/src/user_item.dart b/lib/src/user_item.dart index 14b488c7..ef442440 100644 --- a/lib/src/user_item.dart +++ b/lib/src/user_item.dart @@ -17,13 +17,14 @@ import 'stream_chat_theme.dart'; /// Modify it to change the widget appearance. class UserItem extends StatelessWidget { /// Instantiate a new UserItem - const UserItem( - {Key key, - @required this.user, - this.onTap, - this.onLongPress, - this.onImageTap}) - : super(key: key); + const UserItem({ + Key key, + @required this.user, + this.onTap, + this.onLongPress, + this.onImageTap, + this.selected = false, + }) : super(key: key); /// Function called when tapping this widget final void Function(User) onTap; @@ -37,6 +38,9 @@ class UserItem extends StatelessWidget { /// The function called when the image is tapped final void Function(User) onImageTap; + /// If true the [UserItem] will show a trailing checkmark + final bool selected; + @override Widget build(BuildContext context) { return ListTile( @@ -58,6 +62,15 @@ class UserItem extends StatelessWidget { onImageTap(user); } }), + trailing: selected + ? CircleAvatar( + child: Icon( + StreamIcons.check, + size: 20, + ), + radius: 10, + ) + : null, title: Text(user.name), subtitle: _buildLastActive(context), ); diff --git a/lib/src/user_list_view.dart b/lib/src/user_list_view.dart index 93c21849..f4487dc0 100644 --- a/lib/src/user_list_view.dart +++ b/lib/src/user_list_view.dart @@ -60,6 +60,7 @@ class UserListView extends StatefulWidget { this.userItemBuilder, this.separatorBuilder, this.onImageTap, + this.selectedUsers, this.swipeToAction = false, this.pullToRefresh = true, }) : super(key: key); @@ -119,6 +120,9 @@ class UserListView extends StatefulWidget { /// Set it to false to disable the pull-to-refresh widget final bool pullToRefresh; + /// Sets a blue trailing checkMark in [UserItem] for all the [selectedUsers] + final List selectedUsers; + @override _UserListViewState createState() => _UserListViewState(); } @@ -309,6 +313,7 @@ class _UserListViewState extends State final usersProvider = UsersBloc.of(context); if (i < users.length) { final user = users[i]; + final selected = widget.selectedUsers?.contains(user) ?? false; UserTapCallback onTap; if (widget.onUserTap != null) { @@ -335,6 +340,7 @@ class _UserListViewState extends State onTap: (user) => onTap(user, widget.userWidget), onLongPress: widget.onUserLongPress, onImageTap: widget.onImageTap, + selected: selected, ); } else { return _buildQueryProgressIndicator(context, usersProvider);