Search code examples
flutterdartupgradebeta

The named parameter isn't defined. Error in Flutter project because of upgrade version


ERROR:-

  1. The named parameter 'favoriteItemsAlignment' isn't defined.

  2. The named parameter 'mode' isn't defined.

  3. The named parameter 'dropdownSearchDecoration' isn't defined.

  4. The argument type 'List?' can't be assigned to the parameter type 'List<dynamic Function(dynamic)>'.

Expanded(
                      child: Container(
                        height: 45,
                        child: DropdownSearch(
                          favoriteItemsAlignment: MainAxisAlignment.center, //1. error
                          mode: Mode.DIALOG,  //2. error
                          dropdownSearchDecoration: InputDecoration( //3. error
                            disabledBorder: InputBorder.none,
                            hintText: dropdownCityName,
                            hintStyle: TextStyle(
                              color: Colors.black,
                              fontSize: 12,
                            ),
                          ),
                          items: dropdownItems, //4. error
                          onChanged: dropdownOnChangeds,
                          selectedItem: dropdownSelectedItems,
                          // selectedItem: dropdownSelectedItems,
                        ),
                      ),
                    ),

hey I got this error because i upgrade flutter stable to beta version. than reverse the version again but error is not resolve.


Solution

  • You're using the API of version 3.0.1. Downgrade the library or migrate the code to version 5.0.1

    It should look like this:

    Expanded(
          child: Container(
            height: 45,
            child: DropdownSearch(
              // Instead of this
              //
              // favoriteItemsAlignment: MainAxisAlignment.center,
              // mode: Mode.DIALOG,
              //
              // add this
              popupProps: const PopupProps.dialog(
                favoriteItemProps: FavoriteItemProps(favoriteItemsAlignment: MainAxisAlignment.center),
              ),
    
              // Instead of this
              //
              // dropdownSearchDecoration: InputDecoration(
              //   disabledBorder: InputBorder.none,
              //   hintText: dropdownCityName,
              //   hintStyle: TextStyle(
              //     color: Colors.black,
              //     fontSize: 12,
              //   ),
              // ),
              //
              // add this
              dropdownDecoratorProps: DropDownDecoratorProps(
                dropdownSearchDecoration: InputDecoration(
                  disabledBorder: InputBorder.none,
                  hintText: dropdownCityName,
                  hintStyle: const TextStyle(
                    color: Colors.black,
                    fontSize: 12,
                  ),
                ),
              ),
              items: dropdownItems,
              onChanged: dropdownOnChangeds,
              selectedItem: dropdownSelectedItems,
            ),
          ),
        ),
    

    Regarding the error #4 - you're passing a list of wrong objects (your list contains functions). Could you please say what dropdownItems is? How you define it?