// 这是我的 main.dart 文件
class UserRegistrationPage extends StatefulWidget {
@override
UserRegistrationPageState createState() => UserRegistrationPageState();
}
class UserRegistrationPageState extends State<UserRegistrationPage>{
@override
Widget build(BuildContext context) {
return MaterialApp(
home: new Scaffold(
body: new SingleChildScrollView(
child: new Container(
child: new Form(
child: formUi(),
),
),
),
),
);
}
Widget formUi(){
return new Column(
children: <Widget>[
new Image(
image: new AssetImage("assets/bgtopbar.png"),
fit: BoxFit.cover,
),
new TextFormField(
// margin: new EdgeInsets.all(15.0),
decoration: new InputDecoration(hintText: 'Mobile Number'),
keyboardType: TextInputType.phone,
maxLength: 10,
),
new TextFormField(
decoration: new InputDecoration(hintText: 'First Name'),
maxLength: 20,
),
new TextFormField(
decoration: new InputDecoration(hintText: 'Last Name'),
maxLength: 20,
),
new TextFormField(
decoration: new InputDecoration(hintText: 'Gender'),
maxLength: 10,
),
],
);
}
Run Code Online (Sandbox Code Playgroud)
我只想为表单中的编辑文本字段设置边距,我不想为图像设置。如何为表单中的单个小部件设置边距。我知道这个问题很简单,但我是新手,所以有帮助我来解决这个问题
创建以下方法并根据需要设置边距
Widget allTextFieldWithMargin(){
return Container(
margin: new EdgeInsets.all(15.0), // Or set whatever you want
child: Column(
children: <Widget>[
new TextFormField(
// margin: new EdgeInsets.all(15.0),
decoration: new InputDecoration(hintText: 'Mobile Number'),
keyboardType: TextInputType.phone,
maxLength: 10,
),
new TextFormField(
decoration: new InputDecoration(hintText: 'First Name'),
maxLength: 20,
),
new TextFormField(
decoration: new InputDecoration(hintText: 'Last Name'),
maxLength: 20,
),
new TextFormField(
decoration: new InputDecoration(hintText: 'Gender'),
maxLength: 10,
),
],
),
);
}
Run Code Online (Sandbox Code Playgroud)
并像 belwo 一样调用allTextFieldWithMargin方法
Widget formUi(){
return new Column(
children: <Widget>[
new Image(
image: new AssetImage("assets/bgtopbar.png"),
fit: BoxFit.cover,
),
allTextFieldWithMargin()
],
);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9393 次 |
| 最近记录: |