【发布时间】:2018-10-05 07:59:43
【问题描述】:
我正在构建一个由各种小部件组成的表单,我想将它们全部对齐。
在以下示例中,我使用了 TextFormField、ListTile 等。
问题与 TextFormField > decoration > icon 和 ListTile >leading 的对齐有关。
如您所见,ListTile > 前导绝对不与 TextFormField > 装饰 > 图标对齐。
在文档中,我找不到任何关于如何调整 ListTile > 前导“margin left”的解释
子问题:如何设置 ListTile 标题和副标题的样式,使其看起来像 TextFormField?
我们非常欢迎任何帮助。
源码摘录:
_buildBody() {
return new SafeArea(
top: false,
bottom: false,
child: new Form(
key: _formKey,
autovalidate: false,
child: new SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
/* -- Profile Picture -- */
const SizedBox(height: 24.0),
_buildProfilePicture(),
/* -- Alias -- */
new TextFormField(
decoration: const InputDecoration(
border: const UnderlineInputBorder(),
filled: true,
icon: const Icon(Icons.person),
hintText: 'Enter an alias',
labelText: 'Alias *',
),
onSaved: (String value) {
profile.alias = value;
},
validator: _validateAlias,
),
const SizedBox(height: 24.0),
/* -- Gender -- */
_buildGender(context),
const SizedBox(height: 24.0),
/* -- Self description -- */
new TextFormField(
decoration: const InputDecoration(
border: const OutlineInputBorder(),
hintText: 'Tell us about yourself',
labelText: 'Describe yourself',
),
maxLines: 5,
),
const SizedBox(height: 24.0),
/* -- Save Button -- */
new Center(
child: new RaisedButton(
child: const Text('Save'),
onPressed: _handleSave,
),
),
const SizedBox(height: 24.0),
],
),
),
),
);
}
_buildGender(BuildContext context) {
return new GestureDetector(
child: new ListTile(
leading: new Container(width: 24.0, height: 24.0, color: Colors.red),//const Icon(Icons.casino),
title: const Text('Gender'),
subtitle: new Text(profile.gender),
trailing: const Icon(Icons.arrow_drop_down),
dense: true,
),
onTap: () async {
await showModalBottomSheet<void>(
context: context,
builder: (BuildContext context){
return _buildGenderBottomPicker();
},
);
}
);
}
【问题讨论】:
-
您可以在传递给
leading: ...(和title,subtitle,...)的小部件周围添加填充和边距 -
这与问题无关,但根据材料设计风格指南,您不应使用相邻的两个 FAB 按钮。
标签: flutter