diff --git a/lib/forez/ui/routes/search_users.dart b/lib/forez/ui/routes/search_users.dart new file mode 100644 index 0000000..2b59fd5 --- /dev/null +++ b/lib/forez/ui/routes/search_users.dart @@ -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 searchUser(BuildContext context, UsersList users) async { + return await showSearch( + context: context, delegate: _SearchDelegate(users)); +} + +class _SearchDelegate extends SearchDelegate { + final UsersList _usersList; + + _SearchDelegate(this._usersList) : assert(_usersList != null); + + @override + List 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(); +} diff --git a/lib/forez/ui/screens/forez_directory_screen.dart b/lib/forez/ui/screens/forez_directory_screen.dart index f3969bb..65551ba 100644 --- a/lib/forez/ui/screens/forez_directory_screen.dart +++ b/lib/forez/ui/screens/forez_directory_screen.dart @@ -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 { } @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 { 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 {