feat: add selection property to user list item
This commit is contained in:
+20
-7
@@ -17,13 +17,14 @@ import 'stream_chat_theme.dart';
|
|||||||
/// Modify it to change the widget appearance.
|
/// Modify it to change the widget appearance.
|
||||||
class UserItem extends StatelessWidget {
|
class UserItem extends StatelessWidget {
|
||||||
/// Instantiate a new UserItem
|
/// Instantiate a new UserItem
|
||||||
const UserItem(
|
const UserItem({
|
||||||
{Key key,
|
Key key,
|
||||||
@required this.user,
|
@required this.user,
|
||||||
this.onTap,
|
this.onTap,
|
||||||
this.onLongPress,
|
this.onLongPress,
|
||||||
this.onImageTap})
|
this.onImageTap,
|
||||||
: super(key: key);
|
this.selected = false,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
/// Function called when tapping this widget
|
/// Function called when tapping this widget
|
||||||
final void Function(User) onTap;
|
final void Function(User) onTap;
|
||||||
@@ -37,6 +38,9 @@ class UserItem extends StatelessWidget {
|
|||||||
/// The function called when the image is tapped
|
/// The function called when the image is tapped
|
||||||
final void Function(User) onImageTap;
|
final void Function(User) onImageTap;
|
||||||
|
|
||||||
|
/// If true the [UserItem] will show a trailing checkmark
|
||||||
|
final bool selected;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
@@ -58,6 +62,15 @@ class UserItem extends StatelessWidget {
|
|||||||
onImageTap(user);
|
onImageTap(user);
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
trailing: selected
|
||||||
|
? CircleAvatar(
|
||||||
|
child: Icon(
|
||||||
|
StreamIcons.check,
|
||||||
|
size: 20,
|
||||||
|
),
|
||||||
|
radius: 10,
|
||||||
|
)
|
||||||
|
: null,
|
||||||
title: Text(user.name),
|
title: Text(user.name),
|
||||||
subtitle: _buildLastActive(context),
|
subtitle: _buildLastActive(context),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ class UserListView extends StatefulWidget {
|
|||||||
this.userItemBuilder,
|
this.userItemBuilder,
|
||||||
this.separatorBuilder,
|
this.separatorBuilder,
|
||||||
this.onImageTap,
|
this.onImageTap,
|
||||||
|
this.selectedUsers,
|
||||||
this.swipeToAction = false,
|
this.swipeToAction = false,
|
||||||
this.pullToRefresh = true,
|
this.pullToRefresh = true,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
@@ -119,6 +120,9 @@ class UserListView extends StatefulWidget {
|
|||||||
/// Set it to false to disable the pull-to-refresh widget
|
/// Set it to false to disable the pull-to-refresh widget
|
||||||
final bool pullToRefresh;
|
final bool pullToRefresh;
|
||||||
|
|
||||||
|
/// Sets a blue trailing checkMark in [UserItem] for all the [selectedUsers]
|
||||||
|
final List<User> selectedUsers;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_UserListViewState createState() => _UserListViewState();
|
_UserListViewState createState() => _UserListViewState();
|
||||||
}
|
}
|
||||||
@@ -309,6 +313,7 @@ class _UserListViewState extends State<UserListView>
|
|||||||
final usersProvider = UsersBloc.of(context);
|
final usersProvider = UsersBloc.of(context);
|
||||||
if (i < users.length) {
|
if (i < users.length) {
|
||||||
final user = users[i];
|
final user = users[i];
|
||||||
|
final selected = widget.selectedUsers?.contains(user) ?? false;
|
||||||
|
|
||||||
UserTapCallback onTap;
|
UserTapCallback onTap;
|
||||||
if (widget.onUserTap != null) {
|
if (widget.onUserTap != null) {
|
||||||
@@ -335,6 +340,7 @@ class _UserListViewState extends State<UserListView>
|
|||||||
onTap: (user) => onTap(user, widget.userWidget),
|
onTap: (user) => onTap(user, widget.userWidget),
|
||||||
onLongPress: widget.onUserLongPress,
|
onLongPress: widget.onUserLongPress,
|
||||||
onImageTap: widget.onImageTap,
|
onImageTap: widget.onImageTap,
|
||||||
|
selected: selected,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return _buildQueryProgressIndicator(context, usersProvider);
|
return _buildQueryProgressIndicator(context, usersProvider);
|
||||||
|
|||||||
Reference in New Issue
Block a user