feat: add selection property to user list item

This commit is contained in:
xsahil03x
2020-11-18 00:09:07 +05:30
parent e5b25d8d06
commit 9b36c2348e
2 changed files with 26 additions and 7 deletions
+20 -7
View File
@@ -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),
);
+6
View File
@@ -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<User> selectedUsers;
@override
_UserListViewState createState() => _UserListViewState();
}
@@ -309,6 +313,7 @@ class _UserListViewState extends State<UserListView>
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<UserListView>
onTap: (user) => onTap(user, widget.userWidget),
onLongPress: widget.onUserLongPress,
onImageTap: widget.onImageTap,
selected: selected,
);
} else {
return _buildQueryProgressIndicator(context, usersProvider);