Skip to content

Handling multi-line items in DropdownButton and DropdownMenuItem #9211

@hundeva

Description

@hundeva

Internal: b/140830819

Issue

The following screenshot demonstrates the issue.

If the dropdown is open, the items are correctly displayed as - for example - two line items, but if the dropdown is closed, only the first line will be visible, and the dropdown indicator won't be visible.

Steps to Reproduce

See the following test project:

import 'package:flutter/material.dart';

void main() {
  runApp(new MaterialApp(
    home: new Scaffold(
      appBar: new AppBar(
        title: new Text('Test project'),
      ),

      body: new Padding(
        padding: new EdgeInsets.all(16.0),
        child: new TestStatefulWidget(),
      ),
    ),
  ));
}

class TestStatefulWidget extends StatefulWidget {

  @override
  State<StatefulWidget> createState() => new TestStatefulWidgetState();
}

class TestStatefulWidgetState extends State<TestStatefulWidget> {

  static const List<String> shortItems = const [
    'These',
    'items',
    'are',
    'short',
    'enough',
  ];

  static const List<String> longItems = const [
    'These items will probably be longer than what fits on the screen correctly',
    'Because of this, the icon indicator on the right side will not show',
    'Instead, in development mode, a red indicator will display, showing something is wrong',
  ];

  String shortSpinnerValue = shortItems[0];
  String longSpinnerValue = longItems[0];

  @override
  Widget build(BuildContext context) {
    return new Column(
      mainAxisSize: MainAxisSize.min,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        new DropdownButton(
          value: shortSpinnerValue,
          onChanged: (string) => setState(() => shortSpinnerValue = string),
          items: shortItems.map((string) {
            return new DropdownMenuItem(
              child: new Text(string),
              value: string,
            );
          }).toList(),
        ),

        new DropdownButton(
          value: longSpinnerValue,
          onChanged: (string) => setState(() => longSpinnerValue = string),
          items: longItems.map((string) {
            return new DropdownMenuItem(
              child: new Text(string),
              value: string,
            );
          }).toList(),
        ),
      ],
    );
  }
}

Metadata

Metadata

Assignees

Labels

c: datalossCan result in the user losing their statecustomer: quill (g3)f: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions