Here's what I have on the screen:
https://i.imgur.com/oSblgWD.png
How can I align Last name so it's under First name ? I don't want to put an icon next to Last name, just First name.
Here's the code I have. Thanks.
body: Center(
child: Form(
key: _formKey,
child: Column(
children: <Widget>[
ListTile(
leading: const Icon(Icons.person),
title: new TextField(
decoration: new InputDecoration(
hintText: "First name",
),
),
),
ListTile(
title: new TextField(
decoration: new InputDecoration(
hintText: "Last name",
),
),
),
],
),
)
)
Solution 1: thedarthcoder
You can add an empty Container
with fixed width as leading
to the Last Name TextField
, or you can wrap your Last Name TextField
inside Padding
and provide a some padding
from left.
Example:
ListTile(
leading: Container(
width: 200.0, //You can adjust the width as required
),
title: new TextField(
decoration: new InputDecoration(
hintText: "Last name",
),
),
),
OR
ListTile(
title: Padding(
padding: padding: EdgeInsets.only(left: 200.0) //Adjust as required
child: new TextField(
decoration: new InputDecoration(
hintText: "Last name",
),
),
),
),
Solution 2: Xuzan
There's a quick hack by changing icon color to colors.transparent. I don't know if it's proper way though.
body: Center(
child: Form(
key: _formKey,
child: Column(
children: <Widget>[
ListTile(
leading: const Icon(Icons.person),
title: new TextField(
decoration: new InputDecoration(
hintText: "First name",
),
),
),
ListTile(
leading: const Icon(Icons.person,color: Colors.transparent),
title: new TextField(
decoration: new InputDecoration(
hintText: "Last name",
),
),
),
],
),
)
)
Solution 3: anmol.majhail
Simple & Elegant Way would be to use Padding
Widget.
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Form(
// key: _formKey,
child: Column(
children: <Widget>[
ListTile(
leading: const Icon(Icons.person),
title: new TextField(
decoration: new InputDecoration(
hintText: "First name",
),
),
),
ListTile(
leading: Padding(padding: EdgeInsets.all(16.0)),
title: new TextField(
decoration: new InputDecoration(
hintText: "Last name",
),
),
),
],
),
)),
);
}
Solution 4: Elihu Del Valle
What I've done is giving it an Icon with size 0, the ListTile will save the space even if there is nothing visible