Skip to content

Dropdown null selection & hints #6422

Closed

Description

@tvolkert

Feature request from Customer Leafy:

  • Add the ability to show a dropdown which does not have a selection (yet)
  • Add "hint" text to display in the dropdown when no value is selected
  • Add ability to show error-text for dropdowns, as we'd need to show that a "None" selection would not be valid when submitting a form

Activity

  1. mpcomplete commented on Nov 3, 2016

    @mpcomplete
    Contributor

    The Input rework that @Hixie mentions in #6421 is a prerequisite for most of this.

  2. self-assigned this
    on Nov 16, 2016
  3. HansMuller commented on Nov 22, 2016

    @HansMuller
    Contributor

    Here's an example that demos the requested features.

    import 'package:flutter/material.dart';
    
    class InputContainerDemo extends StatefulWidget {
      @override
      _InputContainerDemoState createState() => new _InputContainerDemoState();
    }
    
    class _InputContainerDemoState extends State<InputContainerDemo> {
      static final List<String> _dropdownItems = <String>['One', 'Two', 'Free', 'Four'];
      String _dropdownValue = 'One';
      String _errorText;
    
      @override
      Widget build(BuildContext context) {
        return new Scaffold(
          appBar: new AppBar(title: new Text('InputContainer Demo')),
          body: new Padding(
            padding: const EdgeInsets.all(32.0),
            child: new DropdownButtonHideUnderline(
              child: new Column(
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: <Widget>[
                  new InputContainer(
                    labelText: _dropdownValue == null ? 'Where are you from' : 'From',
                    errorText: _errorText,
                    isEmpty: _dropdownValue == null,
                    child: new DropdownButton<String>(
                      value: _dropdownValue,
                      isDense: true,
                      onChanged: (String newValue) {
                        setState(() {
                          _dropdownValue = newValue;
                        });
                      },
                      items: _dropdownItems.map((String value) {
                        return new DropdownMenuItem<String>(
                          value: value,
                          child: new Text(value),
                        );
                      }).toList(),
                    ),
                  ),
                  new SizedBox(height: 32.0),
                  new Row(
                    children: <Widget> [
                      new RaisedButton(
                        onPressed: () {
                          setState((){
                            _dropdownValue = null;
                          });
                        },
                        child: new Text('VALUE'),
                      ),
                      new SizedBox(width: 32.0),
                      new RaisedButton(
                        onPressed: () {
                          setState(() {
                            _errorText = _errorText != null ? null : 'error';
                          });
                        },
                        child: new Text('ERROR'),
                      ),
                    ],
                  ),
                ],
              ),
            ),
          )
        );
      }
    }
    
    void main() {
      runApp(new MaterialApp(home: new InputContainerDemo()));
    }
    
  4. gauthamns commented on Feb 12, 2018

    @gauthamns

    InputContainer is now removed from the material library. Any input regarding the new way of doing will be helpful.

  5. Hixie commented on Feb 13, 2018

    @Hixie
    Contributor

    I think we renamed it InputDecorator.

  6. jjerome00 commented on Sep 10, 2018

    @jjerome00

    Using example above, replace the InputContainer Widget with this:

    InputDecorator(
      decoration: InputDecoration(
        labelText: _dropdownValue == null ? 'Where are you from' : 'From',
        errorText: _errorText,
      ),
      isEmpty: _dropdownValue == null,
      child: new DropdownButton<String>(
        value: _dropdownValue,
        isDense: true,
        onChanged: (String newValue) {
          setState(() {
            _dropdownValue = newValue;
          });
        },
        items: _dropdownItems.map((String value) {
          return DropdownMenuItem<String>(
            value: value,
            child: Text(value),
          );
        }).toList(),
      ),
    ),
    
  7. added a commit that references this issue on Oct 4, 2018
  8. hemachandsai commented on May 1, 2020

    @hemachandsai

    Simple fix, add space in the prefix text itself!!

  9. github-actions commented on Aug 21, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  10. locked as resolved and limited conversation to collaborators on Aug 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

c: new featureNothing broken; request for a new capabilityp: material_uimaterial_ui package in flutter/packages

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions