Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some issue with suggestion box #48

Merged
merged 5 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,27 @@ class _MyHomePageState extends State<MyHomePage> {
'dat@gmail.com',
'dab246@gmail.com',
'kaka@gmail.com',
'datvu@gmail.com'
'datvu@gmail.com',
'datvu1@gmail.com',
'datvu2@gmail.com',
'datvu3@gmail.com',
'datvu4@gmail.com',
'datvu5@gmail.com',
'datvu6@gmail.com',
'datvu7@gmail.com',
'datvu8@gmail.com',
'datvu9@gmail.com',
'datvu10@gmail.com',
'datvu11@gmail.com',
'datvu12@gmail.com',
'datvu13@gmail.com',
'datvu14@gmail.com',
'datvu15@gmail.com',
'datvu16@gmail.com',
'datvu17@gmail.com',
'datvu18@gmail.com',
'datvu19@gmail.com',
'datvu20@gmail.com',
];

List<String> _values = [];
Expand Down Expand Up @@ -93,6 +113,9 @@ class _MyHomePageState extends State<MyHomePage> {
delimiters: [',', ' '],
hasAddButton: true,
resetTextOnSubmitted: true,
suggestionsBoxMaxHeight: 200,
isLoadMoreOnlyOnce: true,
isLoadMoreReplaceAllOld: false,
// This is set to grey just to illustrate the `textStyle` prop
textStyle: const TextStyle(color: Colors.grey),
onSubmitted: (outstandingValue) {
Expand Down Expand Up @@ -179,6 +202,27 @@ class _MyHomePageState extends State<MyHomePage> {
},
suggestionsBoxElevation: 10,
findSuggestions: (String query) {
debugPrint(
'_MyHomePageState::build:findSuggestions::query = $query');
if (query.isNotEmpty) {
var lowercaseQuery = query.toLowerCase();
return mockResults.sublist(0, 8).where((profile) {
return profile
.toLowerCase()
.contains(query.toLowerCase()) ||
profile.toLowerCase().contains(query.toLowerCase());
}).toList(growable: false)
..sort((a, b) => a
.toLowerCase()
.indexOf(lowercaseQuery)
.compareTo(
b.toLowerCase().indexOf(lowercaseQuery)));
}
return [];
},
loadMoreSuggestions: (query) {
debugPrint(
'_MyHomePageState::build:_loadMoreSuggestion::query = $query');
if (query.isNotEmpty) {
var lowercaseQuery = query.toLowerCase();
return mockResults.where((profile) {
Expand Down
Loading
Loading