srtraj / dropdown_textfield

custom dropdown
MIT License
8 stars 48 forks source link

Wrong usage of initialValue in multiController condition which gives an error #47

Closed Abdulvaliy closed 3 months ago

Abdulvaliy commented 7 months ago

When I use DropDownTextField with multiSelection to use a multi selectable dropdown with MultiValueDropDownController I always face an issue. When I check the code error shows, I found that wrong usage of widget.initialValue.join(",") instead of widget.multiController!.dropDownValueList items. I suggest you to fix this issue and would be very happy when you do this.

Here is the error I'm facing: Screen Shot 2024-02-04 at 12 36 49

(I think) This is the code needs to be fixed at the line of 432 Screen Shot 2024-02-04 at 12 38 01

srtraj commented 3 months ago

Maybe you're passing an invalid list. Could you please share minimal code to reproduce this issue?

Abdulvaliy commented 3 months ago

@srtraj I'm not using this package for a long time because there is no update.

List was valid, It was working with single selection but when it is time with multi selection some logic was incorrect.

This was the component I was using

...
final List<DropDownValueModel>? dropDownList;
...

type == InputType.multiDropdown
              ? DropDownTextField.multiSelection(
                  /// if InputType is dropdown use [MultiValueDropDownController] for controller property
                  controller: controller as MultiValueDropDownController,
                  clearOption: false,
                  textFieldFocusNode: textFieldFocusNode,
                  searchFocusNode: searchFocusNode,
                  // dropDownItemCount: dropDownList?.length ?? 0,
                  displayCompleteItem: true,
                  dropDownList: dropDownList ?? [],
                  checkBoxProperty: CheckBoxProperty(
                    activeColor: kPrimaryColor,
                    shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(6.0)),
                  ),
                  textStyle: kTextH5,
                  submitButtonColor: kPrimaryColor,
                  submitButtonTextStyle: kTextH6MediumWhite,
                  onChanged: onValueChanged,
                  textFieldDecoration: InputDecoration(
                    fillColor: kSoftColorPrimary,
                    filled: true,
                    border: kOutlineBorder,
                    enabledBorder: 2 > 1 ? kOutlineBorder : kErrorOutlineFocusBorder,
                    focusedBorder: kOutlineFocusBorder.copyWith(
                      borderSide: BorderSide(color: kPrimaryColor.withOpacity(0.5), width: 1.5),
                    ),
                    isDense: true,
                    prefix: prefix,
                    prefixIcon: primaryPrefixIcon(),
                    prefixIconConstraints: const BoxConstraints(maxHeight: 20.0),
                    suffix: suffix(),
                    suffixIcon: trailing,
                    hintText: placeholder,
                    hintStyle: kTextH5.copyWith(color: kGreyShade400),
                  ),
                )

This is usage of component

MyTextInput(
                    controller: teachingSubjectsController,
                    isRequired: true,
                    isEnabled: true,
                    type: InputType.multiDropdown,
                    textInputType: TextInputType.none,
                    label: 'Teaching Subjects',
                    placeholder: 'English, Math',
                    prefixIconSvgAsset: 'star'.svgImage(),
                    dropDownList: organizationTeachingSubjects
                        .map((subject) => DropDownValueModel(
                              name: subject.name,
                              value: subject.id,
                            ))
                        .toList(),
                  ),

As you can see, there was no problem usage. I hope this issue will be resolved in near future.

srtraj commented 3 months ago

Sorry @Abdulvaliy for the delayed reply. I was busy with other things and couldn't maintain this package. I have fixed this issue in latest release dropdown_textfield: ^1.1.0