Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter DropdownButton show label when option is selected

Tags:

flutter

Can a Dropdown Button:

 return DropdownButton<String>(
          items: <String>['Foo', 'Bar'].map((String value) {
            return new DropdownMenuItem<String>(
              value: value,
              child: new Text(value),
            );
          }).toList(),
          onChanged: (_) {},
        );

have something similar to a decoration user in a TextFormField:

      TextFormField(
        controller: _titleController,
        decoration: InputDecoration(labelText: 'Input'),
        validator: (String value) {
          if (value != null && value.isEmpty) {
            return 'Please enter some text';
          }
        },
        style: Theme.of(context).textTheme.title,
      ),

When something is written in the above TextFormField the word Input shows. Like this:

enter image description here

like image 645
Ciprian Avatar asked Jun 01 '19 20:06

Ciprian


People also ask

How do you show the selected value in a dropdown in flutter?

Step 1: Add a variable called dropdownValue that holds the currently selected item. Step 2: Add the DropdownButton widget to your page. Step 3: Inside the DropdownButton, add the value parameter and assign the dropdownValue that we created in step 1.

How do I open dropdown dialog below DropdownButton flutter?

Option 1: Set DropDown. dart selectedItemOffset to -40 in then DropDownItems will always opens below the DropdownButton .


2 Answers

Replace DropdownButton with DropdownButtonFormField:

https://api.flutter.dev/flutter/material/DropdownButtonFormField-class.html

like image 150
dfmiller Avatar answered Sep 17 '22 22:09

dfmiller


Change DropdownButton to DropdownButtonFormField and add this decoration....

              decoration: InputDecoration(
                filled: true,
                fillColor: Hexcolor('#ecedec'),
                labelText: 'Occupation',
                border: new CustomBorderTextFieldSkin().getSkin(),
              ),
like image 40
JayLord Abueva Avatar answered Sep 16 '22 22:09

JayLord Abueva