build method

  1. @override
dynamic build(
  1. dynamic context,
  2. dynamic ref
)

Implementation

@override
Widget build(BuildContext context, WidgetRef ref) {
  final suggestedUsers =
      ref.watch(filteredSuggestedUsersProvider(roomId)).valueOrNull ?? [];

  final foundUsers = ref.watch(searchResultProvider).valueOrNull ?? [];

  if (suggestedUsers.isEmpty && foundUsers.isEmpty) {
    // nothing found
    return Center(
      child: EmptyState(
        title: L10n.of(context).noUserFoundTitle,
        subtitle: L10n.of(context).noUserFoundSubtitle,
        image: 'assets/images/empty_activity.svg',
      ),
    );
  }

  return ListView.builder(
    itemBuilder: (context, position) {
      late UserProfile user;
      bool showRooms = false;
      if (position >= suggestedUsers.length) {
        user = foundUsers[position - suggestedUsers.length];
      } else {
        user = suggestedUsers[position];
        showRooms = true;
      }

      final userWidget =
          userItemBuilder(isSuggestion: showRooms, profile: user);
      if (position == 0 && suggestedUsers.isNotEmpty) {
        return Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Padding(
              padding:
                  const EdgeInsets.symmetric(horizontal: 10.0, vertical: 5.0),
              child: Text(
                L10n.of(context).suggestedUsers,
                style: Theme.of(context).textTheme.titleSmall,
              ),
            ),
            userWidget,
          ],
        );
      }
      if (position == suggestedUsers.length && foundUsers.isNotEmpty) {
        return Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Padding(
              padding:
                  const EdgeInsets.symmetric(horizontal: 10.0, vertical: 5.0),
              child: Text(
                L10n.of(context).usersfoundDirectory,
                style: Theme.of(context).textTheme.titleSmall,
              ),
            ),
            userWidget,
          ],
        );
      }
      return userWidget;
    },
    itemCount: suggestedUsers.length + foundUsers.length,
  );
}