53

How to Add Rounded Rectangle Border? Below Code didn't result in any border on screen.

Container(margin: EdgeInsets.only(top: 10.0, right: 10.0, left: 10.0),
 width: double.infinity,
 // decoration: ShapeDecoration(
 //  shape: RoundedRectangleBorder(
 //   borderRadius:BorderRadius.all(Radius.circular(5.0)),
 //                             ),

 child: DropdownButtonHideUnderline(
  child: Container(
   margin: EdgeInsets.only(
    left: 10.0, right: 10.0),
     child: new DropdownButton<UserTest>(...),
                           ),
                          ),
                   ),
John Ravi
  • 1,190
  • 1
  • 12
  • 21

9 Answers9

79

With the form field variant, you can use the OutlineInputBorder InputBorder, used normally for input text fields:

DropdownButtonFormField(
  ...
  decoration: const InputDecoration(
    border: OutlineInputBorder(),
  ),
),

The way the form field does this can be replicated and used with the regular DropdownButton:

InputDecorator(
  decoration: const InputDecoration(border: OutlineInputBorder()),
  child: DropdownButtonHideUnderline(
    child: DropdownButton(
      ...
    ),
  ),
),

Border preview

hacker1024
  • 3,186
  • 1
  • 11
  • 31
  • I like this answer because it uses DropdownButtonFormField that has a labelText prop, this will keep the input label visible after selecting some value and this is fundamental from a UX perspective. – Nick Jun 23 '20 at 19:14
  • 1
    floatingLabelBehavior doesn't behave properly with the input decorator. Do you know why? – Bagus Aji Santoso Aug 23 '20 at 13:38
  • I'm not sure - maybe check for differences with the form field implementation? – hacker1024 Aug 25 '20 at 01:23
34

You need to specify the side: property. By default it is BorderSide.none.

      decoration: ShapeDecoration(
        shape: RoundedRectangleBorder(
          side: BorderSide(width: 1.0, style: BorderStyle.solid),
          borderRadius: BorderRadius.all(Radius.circular(5.0)),
        ),
      ),
chemamolins
  • 19,400
  • 5
  • 54
  • 47
16

If what you want is this...

enter image description here

Then here you go

    import 'package:flutter/material.dart';

class RoundedBorderDropdown extends StatelessWidget {
  final List<String> _dropdownValues = [
    "One",
    "Two",
    "Three",
    "Four",
    "Five"
  ]; //The list of values we want on the dropdown

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Rounded Border Button in AppBar'),
      ),
      body: Center(
        child: Container(
          padding: EdgeInsets.symmetric(horizontal: 10.0),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(15.0),
            border: Border.all(
                color: Colors.red, style: BorderStyle.solid, width: 0.80),
          ),
          child: DropdownButton(
            items: _dropdownValues
                .map((value) => DropdownMenuItem(
                      child: Text(value),
                      value: value,
                    ))
                .toList(),
            onChanged: (String value) {},
            isExpanded: false,
            value: _dropdownValues.first,
          ),
        ),
      ),
    );
  }
}

That is courtesy inducesmile

Happy Coding...

Roberto Juárez
  • 115
  • 1
  • 4
The Billionaire Guy
  • 3,382
  • 28
  • 31
16

Sample Output

Column(
    crossAxisAlignment : CrossAxisAlignment.start,
    children: <Widget> [
        Text('Gender:'),
        InputDecorator(
            decoration: InputDecoration(
                border: OutlineInputBorder(borderRadius: const BorderRadius.all(Radius.circular(4.0)),
                contentPadding: EdgeInsets.all(10),
            ),
            child: DropdownButtonHideUnderline(
                child: DropdownButton<String>(
                    value: gender,
                    isDense: true,
                    isExpanded: true,
                    items: [
                        DropdownMenuItem(child: Text("Select Gender"), value: ""),
                        DropdownMenuItem(child: Text("Male"), value: "Male"),
                        DropdownMenuItem(child: Text("Female"), value: "Female"),
                    ],
                    onChanged: (newValue) {
                        setState(() {
                        });
                    },
                ),
            ),
        ),
    ]
),
Shourya Shikhar
  • 1,342
  • 1
  • 11
  • 29
2

You can try with this

 Container(
                                  padding: EdgeInsets.symmetric(horizontal: 5),
                                  decoration: BoxDecoration(
                                    border: Border.all(color: Colors.blueGrey),
                                    borderRadius: BorderRadius.circular(5),
                                  ),
                                  child: DropdownButtonHideUnderline(
                                    child: DropdownButton<String>(
                                      borderRadius: BorderRadius.circular(12),
                                      isExpanded: true,
                                      items: <String>[
                                        '1 km',
                                        '2 km',
                                        '3 km',
                                        '4 km',
                                        '5 km'
                                      ].map((String value) {
                                        return DropdownMenuItem<String>(
                                          value: value,
                                          child: Text(value),
                                        );
                                      }).toList(),
                                      hint:
                                          ourtext("Select area", fontSize: 14),
                                      onChanged: (_) {},
                                    ),
                                  ),
                                ),
Amazed
  • 49
  • 2
  • 2
1
Container(width: 200.0,
          height: 50.0,
          decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(7.0),
          border: Border.all(color: Colors.blueGrey)),
                         child: DropdownButton<String>(
                         hint: Text("Messaging"),
                         items: <String>['Messaging', 'Chating', 'No Longer Interested', 'Document Request'].map((String value) {
                            return new DropdownMenuItem<String>(
                              value: value,
                              child: new Text(value),
                            );
                          }).toList(),
                          onChanged: (_) {},
                      ),
                      )
Jiten Basnet
  • 1,623
  • 15
  • 31
0

Wrap it in a Material and remove DropDown borders

Material(
    borderRadius: BorderRadius.circular(40),
    child: SizedBox(
      width: MediaQuery.of(context).size.width / 1.08,
      child: DropdownButton(
        style: style.copyWith(color: Colors.black),
        isExpanded: true,
        underline: DropdownButtonHideUnderline(child: Container()),
        value: value,
        items: ...
   
    ),
  )
0

In case you want to make rounded corners for the menu itself, just add borderRadius properties in DropdownButton:

DropdownButton(
  borderRadius:BorderRadius.circular(12),
  items: ...
)
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
0

String selectedValue

String selected value;

Widget createRoundedDropDown (){
  return Container(
  decoration: BoxDecoration(
    color: Colors.white,
    border: Border.all(),
    borderRadius: BorderRadius.circular(20),
  ),
  child: Padding(
    padding: const EdgeInsets.all(5.0),
    child: DropdownButtonHideUnderline(
      child: DropdownButton<String>(
        borderRadius: BorderRadius.circular(10),
        style: TextStyle(color: Colors.black,fontSize: 14,),
        hint: Text("hint text"),
        value: selectedValue,
        isDense: true,
        onChanged: (newValue) {
          setState(() {
            selectedValue = newValue;
          });
        },
        items: listItems.map((document)  {
          return DropdownMenuItem<String>(
            value: document.name,
            child: FittedBox(fit:BoxFit.fitWidth,
                child: Text(document.name,
                       style:TextStyle(fontSize: 16))),
            );
        }).toList(),
      ),
    ),
  ),
);}
Edimar Martins
  • 2,631
  • 1
  • 9
  • 10