Because of some requirements, I need to support big text size on my app. And because of that I’m having a bit of issue with a DropdownButtonFormField
that contains long text. I was able to fix the right overflow with isExpanded: true
, but now the issue is, I think, DropdownButtonFormField
doesn’t really know how to handle isExpanded: true
properly. Here’s what my DropdownButtonFormField
currently looks like:
Here’s what my code looks like:
ConstrainedBox(
constraints: BoxConstraints(
minHeight: 70.0,
),,
child: DecoratedBox(
decoration: CustomViewStyle.textBoxDecoration,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: DropdownButtonFormField<PermitCertificateType>(
isExpanded: true,
style: CustomTextStyle.textBoxTextStyle,
value: widget.permitCertificateRecord?.permitCertificateType,
decoration: InputDecoration(
hintText: 'Permit/Certificate Type',
hintStyle: CustomTextStyle.dropdownHintTextStyle,
errorStyle: CustomTextStyle.errorStyle
),
hint: Text("Permit/Certificate Type",
style: CustomTextStyle.adapterTextTextStyle,),
items: snapshot.data!.map((PermitCertificateType value) {
return DropdownMenuItem<PermitCertificateType>(
value: value,
child: Wrap(
children: [
Text(value.name,
style: CustomTextStyle.textBoxTextStyle,),
]
),
);
}).toList(),
validator: (value) {
if (value == null) {
return 'Missing Permit/Certificate Type';
}
return null;
},
onChanged: (text) async {
},
onSaved: (value) {
_permitCertificateTypeId = value!.id;
},
),
),
),
),
itemHeight
doesn’t help because it only affects the item of the dropdown itself, not the displayed one after choosing an item or when setting an initial value.
2
Answers
I think I found the easiest solution for this, albeit, may not look that good for single line items. Set the
DropdownButtonFormField
or similar'sisDense
tofalse
. You don't even need aWrap
before theDropdownMenuItem
'sText
.Here's what my current code looks like:
I highly recommend using this code. Here, I manage the short and long text by initially checking whether the text is overflowing or not. If the option is short and not overflowing, it will display as it is; otherwise, it will display as rotating text (AKA Marquee text).
For the rotating text (AKA Marquee text), consider using this package: https://pub.dev/packages/text_marquee