0

first Photo second photo I have a costum dropdown menu and each of the rows have a dropdown button. The problem is that the items of my dropdown button are too long to be fit in one row so can i expand the itemHeight so some of my dropdownButton items fit better and my dropdown button width wont cover my whole listTile? i tried with itemHeight property and its not working here is what happens when i use sized box with height and width: third photo

ListTile(
                                leading: Radio(
                                  value: 1,
                                  groupValue: groupValue1,
                                  onChanged: handleGroupValue1,
                                ),
                                title: Text('vie marine'),
                                trailing: DropdownButton(
                                  itemHeight: 100.0,
                                  dropdownColor: Colors.grey.shade300,
                                  value: ddValue2,
                                  icon: Icon(Icons.keyboard_arrow_down),
                                  elevation: 10,
                                  onChanged: (String newValue) {
                                    setState(() {
                                      ddValue2 = newValue;
                                    });
                                  },
                                  items: [
                                    'select',
                                    'requin'
                                        'mammifere',
                                    'reptile&'
                                        'anguille',//this is an alternative which i want to show in 2 lines, but still be one alternative.
                                    'crustace',
                                    'raie',
                                    'limace&'
                                        'gastropode',
                                    'cephalopode&'
                                        'concombre',
                                    'corail/bivalve'
                                        '/oursin/etoile de mer',
                                    'poisson'
                                        'pelagique',
                                    'poisson'
                                        'de recif',
                                    'poisson'
                                        'de fond',
                                  ].map<DropdownMenuItem<String>>(
                                      (String value) {
                                    return DropdownMenuItem<String>(
                                      value: value,
                                      child: Text(value);
                                  }).toList(),
                                ),
                              ),

1 Answers1

0

You can wrap your Text widget with a SizedBox or with a container and set the height of it as shown below.

ListTile(
                            leading: Radio(
                              value: 1,
                              groupValue: groupValue1,
                              onChanged: handleGroupValue1,
                            ),
                            title: Text('vie marine'),
                            trailing: DropdownButton(
                              dropdownColor: Colors.grey.shade300,
                              value: ddValue2,
                              icon: Icon(Icons.keyboard_arrow_down),
                              elevation: 10,
                              onChanged: (String newValue) {
                                setState(() {
                                  ddValue2 = newValue;
                                });
                              },
                              items: [
                                'select',
                                'requin'
                                    'mammifere',
                                'reptile&'
                                    'anguille',//this is an alternative which i want to show in 2 lines, but still be one alternative.
                                'crustace',
                                'raie',
                                'limace&'
                                    'gastropode',
                                'cephalopode&'
                                    'concombre',
                                'corail/bivalve'
                                    '/oursin/etoile de mer',
                                'poisson'
                                    'pelagique',
                                'poisson'
                                    'de recif',
                                'poisson'
                                    'de fond',
                              ].map<DropdownMenuItem<String>>(
                                  (String value) {
                                return DropdownMenuItem<String>(
                                  value: value,
                                  child: SizedBox(
                                    height: 100,// The height you need to have
                                    child: Text(value));
                              }).toList(),
                            ),
                          ),
Dharman
  • 30,962
  • 25
  • 85
  • 135
LovinduLI
  • 339
  • 4
  • 13