mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-12-26 12:58:51 +00:00
Can search for users
This commit is contained in:
parent
fae18f0abd
commit
8e8a3c711d
53
lib/forez/ui/routes/search_users.dart
Normal file
53
lib/forez/ui/routes/search_users.dart
Normal 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();
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
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/users_helper.dart';
|
||||
import 'package:comunic/lists/group_members_list.dart';
|
||||
@ -43,11 +44,23 @@ class _ForezDirectoryScreenState extends State<ForezDirectoryScreen> {
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => AsyncScreenWidget(
|
||||
onReload: _load,
|
||||
onBuild: onBuild,
|
||||
errorMessage: tr("Failed to load members list!"),
|
||||
key: _key,
|
||||
Widget build(BuildContext context) => Stack(
|
||||
children: [
|
||||
AsyncScreenWidget(
|
||||
onReload: _load,
|
||||
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(
|
||||
@ -86,6 +99,12 @@ class _ForezDirectoryScreenState extends State<ForezDirectoryScreen> {
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user