Comments (3)
Hi evanse9, Much appreciated! Would you mind sharing your code so I can learn from it?
from flutter_choice.
Hi, we were able to resolve the problem. I uploaded 3 images were you can see the List we created, the original Choice.inline widget code and the modified Choice.inline code. In the original code, we used the prewritten methods provided by the Choice package at the level of the 'selected' and 'onselected' properties which is
"selected: selection.selected(_c_k[i]),
onSelected: selection.onSelected( _c_k[i], ),"
but in the modified(fixed) version we created a variable (Selected_car_K) which can hold a certain string and compare it's value to the name(text written on the choice chip) of the choice chip, and if the names are the same, the state of that choice chip is changed and it get selected. This is the code
" selected: Selected_car_K == _c_k[i].K_name ,
onSelected: (value) {
setState(() {
Selected_car_K = value ? _c_k[i].K_name.toString() : 'all' ;
});
},"
So i think the problem was at the level of the state management or the prewritten select method called at the level of the properties 'selected' and 'onselected' or may be i implemented the widget wrongly.
from flutter_choice.
I see! To manage the selected value in your choice
widget, you have two approaches:
-
Updating from outside the widget:
Use the
onChanged
parameter to define a callback function that receives the newly selected value. This function can then update yourselectedValue
variable accordingly. -
Setting the initial value inside the widget:
Set the
value
parameter directly to yourselectedValue
variable. This will automatically populate the widget with the current selection.
Here's a code example that demonstrates both approaches:
InlineChoice<String>.single(
clearable: true,
value: selectedValue, // Set initial value
onChanged: (newValue) { // Handle value changes from outside
setState(() {
selectedValue = newValue;
});
},
itemCount: choices.length,
itemBuilder: (state, i) {
return ChoiceChip(
selected: state.selected(choices[i]),
onSelected: state.onSelected(choices[i]),
label: Text(choices[i]),
);
},
),
from flutter_choice.
Related Issues (10)
- how to change the tigger widget?
- can not scroll
- [Feature Request] Async filter HOT 2
- How to style list wrapper like i want to change list background color HOT 1
- Because xxx depends on choice >=1.0.0-dev.2 which requires SDK version >=3.0.6 <4.0.0, version solving failed.
- Padding around the Choice widget HOT 2
- Few options, always next line
- How to change the display when passing in a list of objects and multiple select of objects?
- how to limit selected count?just like,if choose count more than max enable count ,the first choice will be cancel
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 flutter_choice.