Comments (8)
You can override the ==
operator for the object itself.
or, use some unique value at the object like an id
to be used as value.
from dropdown_button2.
@vasilich6107
Can you check #127 and see if it's what you're looking for?
from dropdown_button2.
What if I have no access to object class?
Imagine that I'm getting user info with role object UserRole
another api returns a list of available roles List<UserRole>
I have to map this classes into custom objects to have an ability to override ==
operator
Otherwise I will have to use id
as value and list of id's
as items and build selected item with searching through the list of items. Ability to override the comparator will make it easy in case of refactoring if you have something already created but you need to change only comparison method
from dropdown_button2.
even if I have an ability to override ==
there are cases when you have a need to change the comparator method on the fly.
You have a list of items, that could be disabled on BE.
One entity assigned to disable person.
So be will return a list of only enabled persons.
at this point you have a need to inject this preselected item into the list of items with updated name 'deactivated` this is the case when it is nice to have comparator update.
Do you see any disadvantages on adding an ability to set custom comparator?
from dropdown_button2.
If it works for you I can create a PR
from dropdown_button2.
Do you see any disadvantages on adding an ability to set custom comparator?
You can set custom comparator by using value
.
I'm not sure what value will this add over doing:
class _MyHomePageState extends State<MyHomePage> {
final List<Item> items = const [
Item('1', 'Item1'),
Item('2', 'Item2'),
Item('3', 'Item3'),
Item('4', 'Item4'),
];
final valueListenable = ValueNotifier<String?>(null);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: DropdownButtonHideUnderline(
child: DropdownButton2<String>(
isExpanded: true,
hint: Text(
'Select Item',
style: TextStyle(
fontSize: 14,
color: Theme.of(context).hintColor,
),
),
items: items
.map((Item item) => DropdownItem<String>(
value: item.id,
height: 40,
child: Text(
item.title,
style: const TextStyle(
fontSize: 14,
),
),
))
.toList(),
valueListenable: valueListenable,
onChanged: (String? value) {
valueListenable.value = value;
},
buttonStyleData: const ButtonStyleData(
padding: EdgeInsets.symmetric(horizontal: 16),
height: 40,
width: 140,
),
),
),
),
);
}
}
class Item {
const Item(this.id, this.title);
final String id;
final String title;
}
from dropdown_button2.
I am experiencing a similar issue. Specifically, I am retrieving a list of users from an API, which includes the currently logged-in user but with less detailed information (same ID, public data, etc.). When I try to set the selected item/object to the logged-in user, the object isn't found because the equality operator (==) is auto-generated by Freezed and I prefer not to modify it.
As a workaround, I could replace the logged-in user in the list if it exists or use just IDs as values, though this approach is less intuitive. What is best approach?
from dropdown_button2.
I am experiencing a similar issue. Specifically, I am retrieving a list of users from an API, which includes the currently logged-in user but with less detailed information (same ID, public data, etc.). When I try to set the selected item/object to the logged-in user, the object isn't found because the equality operator (==) is auto-generated by Freezed and I prefer not to modify it.
As a workaround, I could replace the logged-in user in the list if it exists or use just IDs as values, though this approach is less intuitive. What is best approach?
What's wrong with using id
as value here?
from dropdown_button2.
Related Issues (20)
- Cannot simultaneously update items and values in beta HOT 2
- The splash effect goes above the error / validation text
- Close programatically on Escape pressed HOT 4
- How can i create menu items with exactly height for each element
- Not possible to have label, text and dropdown values all aligned with OutlineInputBorder HOT 2
- Show selected item when page initialized HOT 6
- onChanged doesn't work when using multiValueListenable HOT 2
- DropdownButtonFormField2 initial value
- barrierCoversButton: false property not working
- Not resetting the search querry before reopening the menu breaks the dropdown menu scroll position calculation algorithm
- The package interferes with TextField HOT 1
- Being able to set the errorText
- Ink splashes get displayed over search widget HOT 2
- Disable focus on DropdownItem HOT 11
- How to wrap TapRegion with groupID around DropdownButtonFormField2 to track TapInside / TapOutside with other TapRegions
- The border does not change to red on validation error HOT 5
- On mobile once keyboard open it's pushing the dropdown to top HOT 6
- Use onMenuStateChange & FocusNode for TextField not working
- How to change disabled style?
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 dropdown_button2.