0

can anyone help me get the same style from these textField to my DropDown widget ?

This is the textField widget

TextFormField(
        obscureText: obscureText,
        controller: controller,
        style: TextStyle(color: Colors.white),
        decoration: InputDecoration(
            contentPadding:
                EdgeInsets.symmetric(vertical: 0, horizontal: 12),
            enabledBorder: OutlineInputBorder(
                borderSide: BorderSide(color: Colors.purple[800])),
            border: OutlineInputBorder(
                borderSide: BorderSide(color: Colors.purple[800])),
            focusedBorder: OutlineInputBorder(
              borderSide: BorderSide(color: Colors.purple[800], width: 2.0),
            )),
        validator: validator),

and this my DropDown :

DropdownButton(
                    value: professionChoosed,
                    onChanged: (newValue) {
                      setState(() {
                        professionChoosed = newValue;
                      });
                    },
                    items: professionList.map((valueItem) {
                      return DropdownMenuItem(
                        value: valueItem,
                        child: Text(valueItem),
                      );
                    }).toList(),
                  ),

This is a preview of the simulator : simulator screenshot

3 Answers3

2

Use DropdownButtonFormField instead of DropdownButton

     DropdownButtonFormField(
                decoration: const InputDecoration(
                contentPadding:
                    EdgeInsets.symmetric(vertical: 0, horizontal: 12),
                enabledBorder: OutlineInputBorder(
                    borderSide: BorderSide(color: Colors.purple[800])),
                border: OutlineInputBorder(
                    borderSide: BorderSide(color: Colors.purple[800])),
                focusedBorder: OutlineInputBorder(
                  borderSide: BorderSide(color: Colors.purple[800], width: 2.0),
                )),
                    value: professionChoosed,
                    onChanged: (newValue) {
                      setState(() {
                        professionChoosed = newValue;
                      });
                    },
                    items: professionList.map((valueItem) {
                      return DropdownMenuItem(
                        value: valueItem,
                        child: Text(valueItem),
                      );
                    }).toList(),
                  ),
Diwyansh
  • 2,961
  • 1
  • 7
  • 11
1

You can use DropdownButtonFormField2 from my DropdownButton2 package. It's the same as DropdownButtonFormField but more customizable and have steady dropdown menu below the button. Give it a try!

Package: DropdownButton2

Ahmed Elsayed
  • 538
  • 1
  • 4
  • 11
0

Try below code hope its help to you. refer official documentation here for dropdown

 InputDecorator(
    decoration: const InputDecoration(border: OutlineInputBorder()),
    child: DropdownButtonHideUnderline(
      child: DropdownButton<String>(
        value: dropdownValue,
        isDense: true,
        isExpanded: true,
        onChanged: (String? newValue) {
          setState(() {
            dropdownValue = newValue!;
          });
        },
        items: <String>['One', 'Two', 'Free', 'Four']
            .map<DropdownMenuItem<String>>((String value) {
          return DropdownMenuItem<String>(
            value: value,
            child: Text(value),
          );
        }).toList(),
      ),
    ),
  ),

Your Result Screen -> image

Ravindra S. Patil
  • 11,757
  • 3
  • 13
  • 40