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

not updating options data #74

Closed
aliaafreen opened this issue Mar 8, 2024 · 5 comments
Closed

not updating options data #74

aliaafreen opened this issue Mar 8, 2024 · 5 comments
Labels
question Further information is requested

Comments

@aliaafreen
Copy link

I am using three multi select dropdown, on selection of first dropdown second options should be updated and when select from second dropdown third option list should update.
my logic working fine, fetching data on first dropdown selection but not updating second dropdown options list, show earlier list and so on.

@xhidnoda
Copy link

xhidnoda commented Mar 8, 2024

please provide some code..

@oi-narendra oi-narendra added the question Further information is requested label Mar 10, 2024
@YawarOsman
Copy link

I have exactly the same issue, and they only initialized the items list in the inItState so it won't be updated again until rebuild the widget from start again

@DBDiggity
Copy link

Hello, I'm having the same issue.

Since some code was requested above I'll provide what I have.

class _BodyState extends State<Body> {
  final MultiSelectController<int> _categoryController = MultiSelectController();

  final MultiSelectController<int> _eventController = MultiSelectController();
  List<String> _eventList = [];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    generateEventList();
  }

  @override
  Widget build(BuildContext context) {
    return SafeArea(
        child: Padding(
      padding: EdgeInsets.all(getProportionateScreenWidth(8)),
      child: Container(
        width: double.infinity,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              margin: EdgeInsets.only(bottom: getProportionateScreenHeight(10)),
              child: Text(
                'Choose a category :',
                style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
              ),
            ),
            Container(
              margin: EdgeInsets.only(bottom: getProportionateScreenHeight(10)),
              child: MultiSelectDropDown<int>(
                hint: 'Select A Category',
                onOptionSelected: (List<ValueItem> selectedOptions) {
                  setState(() {
                    generateEventList();
                  });
                },
                controller: _categoryController,
                options: const [
                  ValueItem(label: 'All', value: 1),
                  ValueItem(label: 'Track', value: 2),
                  ValueItem(label: 'Field', value: 3)
                ],
                selectionType: SelectionType.single,
                chipConfig: const ChipConfig(wrapType: WrapType.wrap),
                dropdownHeight: getProportionateScreenHeight(170),
                optionTextStyle: const TextStyle(fontSize: 16),
                selectedOptionIcon: const Icon(Icons.check_circle),
              ),
            ),
            MultiSelectDropDown<int>(
              hint: 'Select from ${_categoryController.selectedOptions.firstOrNull?.label ?? '-'} Event',
              onOptionSelected: (List<ValueItem> selectedOptions) {},
              controller: _eventController,
              options: List.generate(
                  _eventList.length,
                  (index) => ValueItem(
                      label: _eventList[index], value: index)),
              selectionType: SelectionType.single,
              chipConfig: const ChipConfig(wrapType: WrapType.wrap),
              dropdownHeight: 300,
              optionTextStyle: const TextStyle(fontSize: 16),
              selectedOptionIcon: const Icon(Icons.check_circle),
            ),
          ],
        ),
      ),
    ));
  }

  void generateEventList() {
    if (_categoryController.selectedOptions.isNotEmpty) {

      switch (_categoryController.selectedOptions[0].value) {
        case 1:
          _eventList = eventsList;
          break;
        case 2:
          _eventList = trackEvents;
          break;
        case 3:
          _eventList = fieldEvents;
          break;
        default:
          _eventList = [];
          break;
      }
      print(_eventList.length);
    } else {
      _eventList = [];
    }
  }

When I change the value in the "Category" dropdown list, it updates the _eventList variable correctly, and the hint for the "Events" dropdown updates accordingly as well. However, the options for the "Events" dropdown do not update, I only see the empty list. Is there a way around this that I am unaware of?

@xhidnoda
Copy link

Hummm, in my case is works. I Use GetX, so when the first element list is selected in "onOptionSelected" i just call update(); so, you need to recharge the screen to update the second element list.

@oi-narendra
Copy link
Owner

Migrate to the latest version v3.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants