Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter DropdownButtonFormField Overflow on big text

Tags:

flutter

dart

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)))),


                   ),


                 )
like image 864
sathish kumar Avatar asked May 18 '26 01:05

sathish kumar


2 Answers

Inside the Text widget add the overflow property:

 child: Text(label.toString(), overflow: TextOverflow.ellipsis,),

From the docs:

overflowTextOverflow

How visual overflow should be handled.

like image 186
Peter Haddad Avatar answered May 20 '26 00:05

Peter Haddad


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)

              ...
like image 36
Dabbel Avatar answered May 20 '26 02:05

Dabbel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!