首页 > 解决方案 > Flutter ListTile 与单选按钮 3 在一行

问题描述

我正在尝试使用单选按钮广告 ListTile 添加 3 个带有标题的单选按钮,但每个单选按钮的标题都溢出并出现在两行中。如何让它出现在一行中?

这是图片

在此处输入图像描述

这是我用于显示 3 个图块的代码。

             Padding(
                        padding: EdgeInsets.only(left: 5, right: 5),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text("Gender",
                              style: TextStyle(fontSize: 19),),
                            Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Expanded(
                                  child:ListTile(
                                    title: const Text('Female'),
                                    leading: Radio(
                                      fillColor: MaterialStateColor.resolveWith((states) => Color(0XFFB63728)),
                                      value: Gender.female,
                                      groupValue: _gen,
                                      onChanged: (Gender? value) {
                                        setState(() {
                                          _gen = value;
                                        });
                                      },
                                    ),
                                  ),
                                ),
                                Expanded(
                                  child: ListTile(

                                    title: const Text('Male'),
                                    leading: Radio(
                                      fillColor: MaterialStateColor.resolveWith((states) => Color(0XFFB63728)),
                                      value: Gender.male,
                                      groupValue: _gen,
                                      onChanged: (Gender? value) {
                                        setState(() {
                                          _gen = value;
                                        });
                                      },
                                    ),
                                  ),),
                                Expanded(
                                  child:ListTile(
                                    title: const Text('Other'),
                                    leading: Radio(
                                      fillColor: MaterialStateColor.resolveWith((states) => Color(0XFFB63728)),
                                      value: Gender.other,
                                      groupValue: _gen,
                                      onChanged: (Gender? value) {
                                        setState(() {
                                          _gen = value;
                                        });
                                      },
                                    ),
                                  ),
                                ),

                              ],
                            )

标签: androidflutterflutter-layout

解决方案


在 ListTile 中添加 contentPadding 属性:

ListTile(
       contentPadding: EdgeInsets.all(0),

contentPadding 设置 0 删除前导和标题之间的额外空格。

更多信息:https ://api.flutter.dev/flutter/material/ListTile/contentPadding.html


推荐阅读