Flutter 如何缩小按钮的宽度并将其置于中间

Flutter 如何缩小按钮的宽度并将其置于中间,flutter,Flutter,我刚刚开始学习颤振,我有一个包含表单的屏幕,我想知道如何缩小按钮的宽度并将其放在中间 这是代码: Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Ajouter note'), centerTitle: true, backgroundColor: Colors.pink, ), body: Container( padding: E

我刚刚开始学习颤振,我有一个包含表单的屏幕,我想知道如何缩小按钮的宽度并将其放在中间

这是代码:

Widget build(BuildContext context) {
return Scaffold(
  appBar: AppBar(
    title: Text('Ajouter note'),
    centerTitle: true,
    backgroundColor: Colors.pink,
  ),
  body: Container(
    padding: EdgeInsets.all(10.0),
    child: Form(
      key: _formKey,
      child: ListView(
        children: <Widget>[
          TextFormField(
            decoration: InputDecoration(
              hintText: 'Saisir un titre',
            ),
            validator: (value) {
              if (value.isEmpty) {
                return 'Please enter some text';
              }
              return null;
            },
          ),
          SizedBox(
            height: 10.0,
          ),
          TextFormField(
            minLines: 10,
            maxLines: 10,
            decoration: InputDecoration(
              hintText: 'Saisir une déscription',
            ),
            // The validator receives the text that the user has entered.
            validator: (value) {
              if (value.isEmpty) {
                return 'Please enter some text';
              }
              return null;
            },
          ),
          SizedBox(
            height: 10.0,
          ),
          RaisedButton.icon(
            onPressed: () {
              if (_formKey.currentState.validate()) {
                Scaffold.of(context).showSnackBar(
                    SnackBar(content: Text('Processing Data')));
              }
            },
            label: Text(
              'Enregistrer',
              style: TextStyle(
                fontSize: 16.0,
                color: Colors.white,
              ),
            ),
            icon: Icon(
              Icons.save,
              color: Colors.white,
            ),
            color: Colors.pink,
          ),
        ],
      ),
    ),
  ),
);
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:文本(“外部注释”),
标题:对,
背景颜色:Colors.pink,
),
主体:容器(
填充:所有边缘设置(10.0),
孩子:表格(
键:_formKey,
子:ListView(
儿童:[
TextFormField(
装饰:输入装饰(
hintText:“Saisir un titre”,
),
验证器:(值){
if(value.isEmpty){
返回“请输入一些文本”;
}
返回null;
},
),
大小盒子(
身高:10.0,
),
TextFormField(
minLines:10,
最大行数:10,
装饰:输入装饰(
hintText:“我的描述是这样的”,
),
//验证器接收用户输入的文本。
验证器:(值){
if(value.isEmpty){
返回“请输入一些文本”;
}
返回null;
},
),
大小盒子(
身高:10.0,
),
RaisedButton.icon(
已按下:(){
if(_formKey.currentState.validate()){
Scaffold.of(上下文).showSnackBar(
SnackBar(内容:文本(“处理数据”));
}
},
标签:文本(
“Enregister”,
样式:TextStyle(
字体大小:16.0,
颜色:颜色,白色,
),
),
图标:图标(
图标。保存,
颜色:颜色,白色,
),
颜色:颜色。粉红色,
),
],
),
),
),
);

}

一种方法是将
raised按钮
包装在
填充中

只能在水平轴上应用填充

Padding(
   padding: const EdgeInsets.symmetric(horizontal: 40),
   child: // your RaisedButton
}

一种方法是将
RaisedButton
包装在
填充中

只能在水平轴上应用填充

Padding(
   padding: const EdgeInsets.symmetric(horizontal: 40),
   child: // your RaisedButton
}

有很多方法可以做到这一点。一个选项是限制按钮的大小,如下所示:

 Center(
      child: SizedBox(
        width: 100,
        child: RaisedButton(
          ...
         ),
      ),
    )

有很多方法可以做到这一点。一个选项是限制按钮的大小,如下所示:

 Center(
      child: SizedBox(
        width: 100,
        child: RaisedButton(
          ...
         ),
      ),
    )