gpt4 book ai didi

Flutter 如何在表单中为特定小部件设置边距

转载 作者:行者123 更新时间:2023-12-04 12:00:37 25 4
gpt4 key购买 nike

//这是我的 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,
),
],
);
}

我只想为表单中的编辑文本字段设置边距,我不想为图像设置。如何为表单中的单个小部件设置边距。我知道这个问题很简单,但我是新手,所以有帮助我来解决这个问题

最佳答案

创建以下方法并根据需要设置边距

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,
),
],
),
);
}

并调用 allTextFieldWithMargin 像belwo这样的方法
 Widget formUi(){
return new Column(
children: <Widget>[
new Image(
image: new AssetImage("assets/bgtopbar.png"),
fit: BoxFit.cover,
),
allTextFieldWithMargin()
],
);
}

关于Flutter 如何在表单中为特定小部件设置边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53884092/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com