[英]Flutter dart: How to separate the space between Text and TextField and also bring together RadioListTile?
I'm learning Flutter.我正在学习 Flutter。 I have a problem (see image below).
我有一个问题(见下图)。 I would like to separate the space between Text "sex" and TextField "name".
我想分隔文本“性别”和文本字段“名称”之间的空格。 I would also like to bring together RadioListTile, they are very separate.
我还想把 RadioListTile 放在一起,它们是很独立的。 Is it possible to do that?
有可能这样做吗? Follow my code
按照我的代码
class _AlertDialogWidgetState extends State<AlertDialogWidget> {
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: ListBody(
children: <Widget>[
TextField(
autofocus: true,
decoration: InputDecoration(
contentPadding: new EdgeInsets.symmetric(vertical: 10.0, horizontal: 10.0),
border: OutlineInputBorder(), hintText: "New user"),
onChanged: (text) => widget.name = text,
),
Text(
'Sex',
textAlign: TextAlign.left,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontWeight: FontWeight.bold),
),
RadioListTile(
title: Text("Female"),
value: "female",
groupValue: widget.sex,
onChanged: (String value) {
setState(() {
widget.sex = value;
});
},
),
RadioListTile(
title: Text("Male"),
value: "male",
groupValue: widget.sex,
onChanged: (String value) {
setState(() {
widget.sex = value;
});
},
),
RadioListTile(
title: Text("Other"),
value: "other",
groupValue: widget.sex,
onChanged: (String value) {
setState(() {
widget.sex = value;
});
},
),
],
),
);
}
}
Wrap your TextField
with Padding
to put more space between TextField
and Text
like this:用
Padding
包裹您的TextField
以在TextField
和Text
之间放置更多空间,如下所示:
Padding(
padding: EdgeInsets.only(top: 15),
child: Text(
'Sex',
textAlign: TextAlign.left,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontWeight: FontWeight.bold),
),
),
For RadioListTile
, you cannot change the padding of radio, but you could use Radio
wrapped with ListTile
and set its alignment to have it closer to the title:对于
RadioListTile
,您无法更改收音机的填充,但您可以使用带有ListTile
的Radio
并将其 alignment 设置为更接近标题:
ListTile(
title: Align(
child: new Text("Female"),
alignment: Alignment(-1.2, 0),
),
leading: Radio(
value: "female",
groupValue: 'F',
onChanged: (String value) {
setState(() {
widget.sex = value;
});
},
),
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.