1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-30 00:36:28 +00:00
comunicmobile/lib/forez/ui/routes/search_users.dart

54 lines
1.4 KiB
Dart
Raw Normal View History

2021-04-25 15:43:51 +00:00
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?>(
2021-04-25 15:43:51 +00:00
context: context, delegate: _SearchDelegate(users));
}
class _SearchDelegate extends SearchDelegate<User?> {
2021-04-25 15:43:51 +00:00
final UsersList _usersList;
2022-03-11 15:27:01 +00:00
_SearchDelegate(this._usersList);
2021-04-25 15:43:51 +00:00
@override
List<Widget>? buildActions(BuildContext context) => null;
2021-04-25 15:43:51 +00:00
@override
Widget buildLeading(BuildContext context) => IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () => this.close(context, null),
);
@override
Widget buildSuggestions(BuildContext context) {
final List<User> list = _usersList
2021-04-25 15:43:51 +00:00
.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();
}