微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我想在我的下拉按钮颤动中更改项目高度

如何解决我想在我的下拉按钮颤动中更改项目高度

first Photo second photo 我有一个服装下拉菜单,每一行都有一个下拉按钮。问题是我的下拉按钮的项目太长而不能放在一行中,所以我可以扩展 itemHeight 以便我的一些 dropdownButton 项目更适合并且我的下拉按钮宽度不会覆盖我的整个 listTile? 我尝试使用 itemHeight 属性但它不起作用 这是当我使用具有高度和宽度的大小框时会发生什么: 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(),

解决方法

您可以使用 SizedBox 或容器包裹您的 Text 小部件,并如下所示设置其高度。

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。