Comments (8)
Hi @joshwhitehouse ,
Thanks for reporting this issue.
It might be related to the way the search matching function is implemented.
Can you please share your code so that I can have a look?
from search_choices.
Hi,
Thanks for you reply! I'm using pretty much the same search matching function you are.
Here is my implementation code. The Countries object is from a database. Let me know if there is anything else you need.
BTW, this is a terrific package you've developed, I have tried a couple of others, but yours is definitely better for my use!
Best,
Josh
class LocationsCountrySearchWidget extends StatelessWidget {
const LocationsCountrySearchWidget({super.key});
@override
Widget build(BuildContext context) {
return SearchChoices<Countries>.single(
style: TextStyle(fontSize: 14, color: blueColor),
hint: "Select a Country",
searchHint: "Select a Country",
onChanged: (country) {
// set a value in the Provider store
},
items: getCountries(context: context),
value: null,
searchFn: (String keyword, items) {
List<int> ret = [];
if (items != null && keyword.isNotEmpty) {
keyword.split(" ").forEach((k) {
int i = 0;
items.forEach((item) {
if (!ret.contains(i) &&
k.isNotEmpty &&
(item.child
.toString()
.toLowerCase()
.contains(k.toLowerCase()))) {
ret.add(i);
}
i++;
});
});
}
if (keyword.isEmpty) {
ret = Iterable<int>.generate(items.length).toList();
}
return (ret);
},
dialogBox: true,
isExpanded: true,
clearSearchIcon: const Icon(
Icons.backspace,
color: Color.fromRGBO(33, 150, 243, 1),
),
);
}
List<DropdownMenuItem<Countries>>? getCountries(
{required BuildContext context}) {
final realmServices = Provider.of<RealmServices>(context, listen: false);
late RealmResults<Countries> countries = realmServices.realm
.query<Countries>('TRUEPREDICATE SORT(country_name ASC)');
List<DropdownMenuItem<Countries>> dropDownList = countries
.map((country) => DropdownMenuItem(
value: country,
child: Text(country.countryName),
))
.toList();
return dropDownList;
}
}
from search_choices.
Hi @joshwhitehouse ,
Thanks a lot for your message, this means a lot to me!
I was not able to try your code but I spotted a difference with the example that may explain the behavior you noticed:
In your code:
item.child // Using the item.child means you are taking the Text Widget instead of a String value. When using .toString() on it while in debug, this may work but not in release.
.toString()
.toLowerCase()
.contains(k.toLowerCase())
In the example:
item.value // The example uses the item.value which, in the example, is a String.
.toString()
.toLowerCase()
.contains(k.toLowerCase())
Since your items
contains a value which contains a property called countryName
, what you want to do is probably the following:
Likely working in your case:
item.value.countryName // In your case, the value.countryName is likely the String you want to search against.
.toString()
.toLowerCase()
.contains(k.toLowerCase())
I hope this will solve your issue.
from search_choices.
I just noticed the same thing myself! I had already changed it to item.value.countryName instead of the item.child (which is a Text). It worked on the simulator just now using item.value.countryName, I'm going to test it on the iPhone right now, and will confirm it works as soon as I do. Many, many thanks!
from search_choices.
That's great, thanks for letting me know. Fingers crossed for the release/device test.
from search_choices.
Yes! that fixed it fine on the device as well! Thanks so much for having a look!
Best,
Josh
from search_choices.
closed
from search_choices.
Thanks to you Josh for this great news!
from search_choices.
Related Issues (20)
- futureSearchFn delays requests instead of debounce them HOT 9
- build failed after flutter upgrade HOT 9
- Customize future search order and filter icons HOT 10
- selectedValueWidgetFn creates an error. HOT 11
- [FEATURE REQUEST] - Wrap items of SearchChoices.multiple() widget HOT 11
- When using futureSearchFn type 'String' is not a subtype of type 'DropdownMenuItem<String>' HOT 2
- searchFn seems to have issues with custom classes in release mode HOT 5
- [Improves] New style HOT 7
- Android fails with gradle 8 HOT 2
- Selected value in SearchChoice.single not working in Mobile but works fine in Web HOT 5
- RTL support - dropdown button has to be on the left side when RTL locale selected in app HOT 7
- Remove the margin/padding in sides & redesign options buttons HOT 7
- Problems for install search_choices version 2.2.7
- Update value from outside the plugin doesn't work
- How delete value selected from a buttom
- Duplicate class kotlin.collections.jdk8.CollectionsJDK8Kt found HOT 1
- futureSearchFn does not work with Custom Object HOT 6
- Clear button is always disabled HOT 3
- Upgrade to latest gradle version
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from search_choices.