admin管理员组

文章数量:1123707

I have a DropdownButton2 widget in which searching is there based on 2 parts: a number before a space and some text after the space in the "child" of DropdownMenuItem. The searching is working correctly for 2 parts in debug mode but not working at all in release mode.

I want to search with both the 1st part and the 2nd part i.e. the number and the text. Is there anything I need to add for the release mode?

Please help!

Here is the code:

List<MyParts> myPartList = snapshot.data!;

 List<DropdownMenuItem<String>> dropdownPartNumbers =
      myPartList.map<DropdownMenuItem<String>>((item) {
    String rawmatName = item.rawmatname!.length > 10
        ? "${item.rawmatname!.substring(0, 10)}..."
        : item.rawmatname!;
    return DropdownMenuItem<String>(
      value: "${item.rawmatcode}-${item.serialNocapture}",
      child: Text("${item.rawmatcode!} ($rawmatName)"),
    );
  }).toList();

// DropdownButton2 widget:
DropdownButtonHideUnderline(
    child: DropdownButton2<String>(
      isExpanded: true,
      hint: Text(
        'Select Part',
        style: TextStyle(
          fontSize: 14,
          color: Theme.of(context).hintColor,
        ),
      ),
      items: dropdownPartNumbers,
      value: _selectedValues[index],
      onChanged: (value) {
        setState(() {
          _selectedValues[index] = value!;
          if (value.contains("Y")) {
            _qtyValues[index] = 1;
            _isReadOnlyList[index] = true;
          } else {
            _isReadOnlyList[index] = false;
          }
          _isVisibleList[index] = value.contains("Y");
        });
      },
      buttonStyleData: const ButtonStyleData(
        padding: EdgeInsets.symmetric(horizontal: 16),
        height: 60,
        width: 200,
      ),
      dropdownStyleData: const DropdownStyleData(
        maxHeight: 350,
      ),
      menuItemStyleData: const MenuItemStyleData(
        height: 60,
      ),
      dropdownSearchData: DropdownSearchData(
        searchController: searchController,
        searchInnerWidgetHeight: 100,
        searchInnerWidget: Container(
          height: 60,
          padding: const EdgeInsets.only(
            top: 8,
            bottom: 4,
            right: 8,
            left: 8,
          ),
          child: TextFormField(
            expands: true,
            maxLines: null,
            controller: searchController,
            decoration: InputDecoration(
              isDense: true,
              contentPadding: const EdgeInsets.symmetric(
                horizontal: 10,
                vertical: 8,
              ),
              hintText: 'Search for part...',
              hintStyle: const TextStyle(fontSize: 14),
              border: OutlineInputBorder(
                borderRadius: BorderRadius.circular(8),
              ),
            ),
          ),
        ),
        searchMatchFn: (item, searchValue) {
          final lowerCaseValue =
              searchValue.toLowerCase();

          final parts = item.child
              .toString()
              .toLowerCase()
              .split(" ");
          final firstPart = parts[0];
          final secondPart = parts.length > 1
              ? parts.sublist(1).join(" ")
              : "";

          return firstPart.contains(lowerCaseValue) ||
              secondPart.contains(lowerCaseValue);
          
        },
      ),
      //This to clear the search value when you close the menu
      onMenuStateChange: (isOpen) {
        if (!isOpen) {
          searchController.clear();
        }
      },
    ),
  )





本文标签: dropdownSearching in dropdownButton2 in flutter is not working in release modeStack Overflow