简体   繁体   中英

Flutter dropdownbutton add decoration error

How to add the flutter DropdownButton a decoration to add some designs on it. It seems when I wrap it with container it gives me a bunch of errors on decoration with BoxDecoration method and I don't fully understand. See my code below:

Container genderDropdownContainer() {
return new Container(
  color: getColor(ColorList.WhiteCream, 1.0),
  decoration: new BoxDecoration(
    borderRadius: BorderRadius.circular(textFieldHeight/2),
    border: Border.all(color: Color.fromRGBO(112, 112, 112, 1.0), width: 1.0)
  ),
  child: selectGenderDropdown(), //DropDownButton
  );
}

Thanks!

You should return a Widget instead of Container. Also, you cannot use both color and decoration property when you are decorating a container. Instead, change the color property of the BoxDecoration.

Widget genderDropdownContainer() {
return new Container(
  decoration: new BoxDecoration(
    color: getColor(ColorList.WhiteCream, 1.0),
    borderRadius: BorderRadius.circular(textFieldHeight/2),
    border: Border.all(color: Color.fromRGBO(112, 112, 112, 1.0), width: 1.0)
  ),
  child: selectGenderDropdown(), //DropDownButton
  );
}

Add border to a widget. Ex-

 new Container(
                    padding: const EdgeInsets.all(3.0),
                    decoration: new BoxDecoration(
                        borderRadius:BorderRadius.all(Radius.circular(2.0)),
                        border: new Border.all(color: Colors.black38)
                    ),
                    child: selectGenderDropdown(),

        ),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM