GithubHelp home page GithubHelp logo

Comments (3)

davigmacode avatar davigmacode commented on June 14, 2024

Hi evanse9, Much appreciated! Would you mind sharing your code so I can learn from it?

from flutter_choice.

evanse9 avatar evanse9 commented on June 14, 2024

simple_list
choice_orginal
choice_FIXED

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.

davigmacode avatar davigmacode commented on June 14, 2024

I see! To manage the selected value in your choice widget, you have two approaches:

  1. 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 your selectedValue variable accordingly.

  2. Setting the initial value inside the widget:

    Set the value parameter directly to your selectedValue 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.