1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 04:49:21 +00:00

Can search for users

This commit is contained in:
Pierre HUBERT 2021-04-25 17:43:51 +02:00
parent fae18f0abd
commit 8e8a3c711d
2 changed files with 77 additions and 5 deletions

View File

@ -0,0 +1,53 @@
import 'package:comunic/lists/users_list.dart';
import 'package:comunic/models/user.dart';
import 'package:comunic/ui/widgets/account_image_widget.dart';
import 'package:flutter/material.dart';
/// Search for users
///
/// @author Pierre Hubert
Future<User> searchUser(BuildContext context, UsersList users) async {
return await showSearch<User>(
context: context, delegate: _SearchDelegate(users));
}
class _SearchDelegate extends SearchDelegate<User> {
final UsersList _usersList;
_SearchDelegate(this._usersList) : assert(_usersList != null);
@override
List<Widget> buildActions(BuildContext context) => null;
@override
Widget buildLeading(BuildContext context) => IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () => this.close(context, null),
);
@override
Widget buildSuggestions(BuildContext context) {
final list = _usersList
.where((element) =>
element.fullName.toLowerCase().contains(query.toLowerCase()))
.toList();
return ListView.builder(
itemCount: list.length,
itemBuilder: (c, i) {
final e = list[i];
return ListTile(
title: Text(e.fullName),
leading: AccountImageWidget(user: e),
onTap: () {
query = e.fullName;
close(context, e);
},
);
});
}
@override
Widget buildResults(BuildContext context) => Container();
}

View File

@ -1,4 +1,5 @@
import 'package:comunic/forez/helpers/forez_group_helper.dart'; import 'package:comunic/forez/helpers/forez_group_helper.dart';
import 'package:comunic/forez/ui/routes/search_users.dart';
import 'package:comunic/helpers/groups_helper.dart'; import 'package:comunic/helpers/groups_helper.dart';
import 'package:comunic/helpers/users_helper.dart'; import 'package:comunic/helpers/users_helper.dart';
import 'package:comunic/lists/group_members_list.dart'; import 'package:comunic/lists/group_members_list.dart';
@ -43,11 +44,23 @@ class _ForezDirectoryScreenState extends State<ForezDirectoryScreen> {
} }
@override @override
Widget build(BuildContext context) => AsyncScreenWidget( Widget build(BuildContext context) => Stack(
onReload: _load, children: [
onBuild: onBuild, AsyncScreenWidget(
errorMessage: tr("Failed to load members list!"), onReload: _load,
key: _key, onBuild: onBuild,
errorMessage: tr("Failed to load members list!"),
key: _key,
),
Positioned(
child: FloatingActionButton(
onPressed: _doSearch,
child: Icon(Icons.search),
),
right: 20,
bottom: 20,
),
],
); );
Widget onBuild() => ListView.builder( Widget onBuild() => ListView.builder(
@ -86,6 +99,12 @@ class _ForezDirectoryScreenState extends State<ForezDirectoryScreen> {
snack(context, tr("Error while processing action!")); snack(context, tr("Error while processing action!"));
} }
} }
void _doSearch() async {
final user = await searchUser(context, UsersList()..addAll(_users));
print("found ${user?.fullName}");
//if (user != null) _openUserProfile(user);
}
} }
class _ForezMemberTile extends StatelessWidget { class _ForezMemberTile extends StatelessWidget {