'Flutter DropdownButtonFormField Overflow on big text
Friends,
I working on DropdownButtonFormField in flutter. It get overflow if menuitem is very big text. can anyone please suggest how to overcome this issue.
Thanks in advance.
Padding(
padding: const EdgeInsets.fromLTRB(0, 20, 0, 0),
child:
DropdownButtonFormField<String>(
value: _paperController,
validator: (value) {
if (value == null) {
return "Select Paper";
}
},
items: Paper_data.map((label) => DropdownMenuItem(
child: Text(label.toString()),
value: label,
))
.toList(),
onChanged: (value) {
setState(() {
_paperController = value;
});
},
hint: Text('Select Paper'),
decoration: InputDecoration(
border: OutlineInputBorder(
borderSide: BorderSide(
color: Color(0xffCED0D2), width: 1),
borderRadius:
BorderRadius.all(Radius.circular(6)))),
),
)
Solution 1:[1]
Inside the Text widget add the overflow property:
child: Text(label.toString(), overflow: TextOverflow.ellipsis,),
From the docs:
overflow?TextOverflowHow visual overflow should be handled.
Solution 2:[2]
I had to add isExpanded: true and overflow: TextOverflow.ellipsis.
SizedBox(
width: 200.0,
child:
DropdownButtonFormField<String>(
isExpanded: true,
...
DropdownMenuItem(
child: Text('YOUR_NAME',
overflow: TextOverflow.ellipsis)
...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Community |
| Solution 2 | Dabbel |
