Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何拥有与appbar相同宽度的按钮?_Flutter - Fatal编程技术网

Flutter 如何拥有与appbar相同宽度的按钮?

Flutter 如何拥有与appbar相同宽度的按钮?,flutter,Flutter,摘要: 目前我有一个结果: 我的目标是得到这个结果(所有元素都对齐): 说明: 我定义了一个标准的appBar、FlatButton和textField。我想让所有元素的宽度和垂直对齐。 默认的appBar和TextField具有相同的宽度,但不是我的按钮。那么,如何使按钮具有与其他元素相同的宽度呢? 代码: import 'package:flutter/material.dart'; /// Styles class Homepage extends StatelessWi

摘要:
目前我有一个结果:

我的目标是得到这个结果(所有元素都对齐):


说明:
我定义了一个标准的appBar、FlatButton和textField。我想让所有元素的宽度和垂直对齐。 默认的appBar和TextField具有相同的宽度,但不是我的按钮。那么,如何使按钮具有与其他元素相同的宽度呢?

代码:

    import 'package:flutter/material.dart';

/// Styles
class Homepage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Test", style: TextStyle(color: Colors.white)),
        centerTitle: true,
        backgroundColor: Colors.black,
      ),

      body: Stack(children: <Widget>[
        new Container(
          height: MediaQuery.of(context).size.height,
          width: MediaQuery.of(context).size.width,

          child: SingleChildScrollView(
            child: Container(
              child: Center(
                child: Column(
                  children: <Widget>[
                    SizedBox(
                      height: 50,
                    ),

                     new ButtonTheme(
                      //minWidth: 300,
                      child: FlatButton(
                      color: Colors.black,
                      child: Text('Play', style: TextStyle(fontSize: 18, color: Colors.white)),
                      onPressed: () {
                        // Perform some action
                      },
                    ),

                ),
                    SizedBox(
                      height: 50,
                    ),
                    new ListTile(
                      leading: const Icon(Icons.person),
                      title: new TextField(
                        decoration: new InputDecoration(
                          hintText: "Name Player 1",
                        ),
                      ),
                    ),                    
                  ],
                ),
              ),
            ),
          ),
        ),
      ]),
    );
  }
}
导入“包装:颤振/材料.省道”;
///风格
类主页扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:文本(“测试”,样式:TextStyle(颜色:Colors.white)),
标题:对,
背景颜色:Colors.black,
),
主体:堆栈(子对象:[
新容器(
高度:MediaQuery.of(context).size.height,
宽度:MediaQuery.of(context).size.width,
子:SingleChildScrollView(
子:容器(
儿童:中心(
子:列(
儿童:[
大小盒子(
身高:50,
),
新钮扣(
//最小宽度:300,
孩子:扁平按钮(
颜色:颜色,黑色,
子项:文本('Play',样式:TextStyle(fontSize:18,颜色:Colors.white)),
已按下:(){
//执行一些操作
},
),
),
大小盒子(
身高:50,
),
新ListTile(
前导:常量图标(Icons.person),
标题:新文本字段(
装饰:新的输入装饰(
hintText:“命名玩家1”,
),
),
),                    
],
),
),
),
),
),
]),
);
}
}

使用一个无限宽的
大小框
使您的
扁平按钮
填充水平空间,然后将其用
填充物
AppBar
填充物为16):

填充(
填充:常量边集。对称(垂直:0,水平:16),
孩子:大小盒子(
宽度:double.infinity,
孩子:扁平按钮(
onPressed:null,
孩子:文本(“玩耍”),
),
),
);

使用一个无限宽的
大小框
使您的
扁平按钮
填充水平空间,然后将其用
填充物
AppBar
填充物为16):

填充(
填充:常量边集。对称(垂直:0,水平:16),
孩子:大小盒子(
宽度:double.infinity,
孩子:扁平按钮(
onPressed:null,
孩子:文本(“玩耍”),
),
),
);

发现哪些小部件正在使用带填充/边距/等的空间的好方法是启用“显示调试绘制”,发现哪些小部件正在使用带填充/边距/等的空间的好方法是启用中的“显示调试绘制”