Skip to content

Instantly share code, notes, and snippets.

@shihaohong
Last active September 25, 2019 09:24
Show Gist options
  • Save shihaohong/378a75548e57e18ec3db49fec9c02033 to your computer and use it in GitHub Desktop.
Save shihaohong/378a75548e57e18ec3db49fec9c02033 to your computer and use it in GitHub Desktop.
dropdown button not properly scaled with tall item
// Flutter code sample for
// This sample shows a `DropdownButton` with a customized icon, text style,
// and underline and whose value is one of "One", "Two", "Free", or "Four".
//
// ![A screenshot of the dropdown button](https://flutter.github.io/assets-for-api-docs/assets/material/dropdown_button.png)
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
/// This Widget is the main application widget.
class MyApp extends StatelessWidget {
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: MyStatefulWidget(),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
MyStatefulWidget({Key key}) : super(key: key);
@override
_MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
String dropdownValue = 'One';
List<String> items = <String>['One', 'Two', 'A repeating, long selection. A repeating, long selection. A repeating, long selection. A repeating, long selection. A repeating, long selection. A repeating, long selection. A repeating, long selection. A repeating, long selection. ', 'Four'];
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: <Widget>[
DropdownButton<String>(
isExpanded: true,
value: dropdownValue,
icon: Icon(Icons.arrow_downward),
iconSize: 24,
elevation: 16,
style: TextStyle(color: Colors.deepPurple),
onChanged: (String newValue) {
setState(() {
dropdownValue = newValue;
});
},
items: items.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment