This repository has been archived by the owner on Jan 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
183 additions
and
59 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import 'package:flappy_search_bar/flappy_search_bar.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:mentorship_client/remote/api_manager.dart'; | ||
import 'package:mentorship_client/remote/models/user.dart'; | ||
import 'package:mentorship_client/screens/member_profile/member_profile.dart'; | ||
import 'package:mentorship_client/widgets/loading_indicator.dart'; | ||
|
||
class SearchPage extends StatelessWidget { | ||
final SearchBarController<User> _searchBarController = SearchBarController(); | ||
Future<List<User>> getSearchNames(String search) async { | ||
final body = await ApiManager.callSafely( | ||
() => ApiManager.instance.userService.getSearchNames(search: search)); | ||
List<User> users = []; | ||
|
||
for (var user in body) { | ||
users.add(User.fromJson(user)); | ||
} | ||
return users; | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
body: SafeArea( | ||
child: SearchBar<User>( | ||
iconActiveColor: Theme.of(context).primaryColor, | ||
searchBarPadding: EdgeInsets.symmetric(horizontal: 10), | ||
searchBarController: _searchBarController, | ||
hintText: "Start typing", | ||
placeHolder: Center( | ||
child: Text("Enter atleast 3 letters"), | ||
), | ||
emptyWidget: Center( | ||
child: Text("No users found"), | ||
), | ||
onSearch: getSearchNames, | ||
minimumChars: 3, | ||
loader: LoadingIndicator(), | ||
onItemFound: (User user, int index) { | ||
return Container( | ||
child: ListTile( | ||
leading: Icon( | ||
Icons.person, | ||
size: 36, | ||
color: Theme.of(context).primaryColor, | ||
), | ||
title: Text(user.name), | ||
isThreeLine: true, | ||
subtitle: Text(user.username), | ||
onTap: () { | ||
Navigator.of(context).push( | ||
MaterialPageRoute( | ||
builder: (context) => MemberProfileScreen(user: user), | ||
), | ||
); | ||
}, | ||
), | ||
); | ||
}, | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.