【问题标题】:Flutter ButtonBar Children SizeFlutter ButtonBar 儿童尺寸
【发布时间】:2019-10-23 20:08:27
【问题描述】:

我正在使用 Flutter 开发一个应用程序,我想使用 ButtonBar。然而,当试图让孩子们利用空间时,按钮只利用最小的空间

        Padding(
          padding: const EdgeInsets.all(8.0),
          child: ButtonBar(
            mainAxisSize: MainAxisSize.max,
            alignment: MainAxisAlignment.center,
            children: <Widget>[
              RaisedButton(
                child: Text('Save'),
                onPressed: () {
                  Navigator.push(context,
                      MaterialPageRoute(builder: (context) => OtpPage()));
                },
              ),
            ],
          ),
        ),

        Padding(
          padding: const EdgeInsets.all(8.0),
          child: ButtonBar(
            mainAxisSize: MainAxisSize.max,
            alignment: MainAxisAlignment.center,
            children: <Widget>[
              RaisedButton(
                child: Text('Save'),
                onPressed: () {
                  Navigator.push(context,
                      MaterialPageRoute(builder: (context) => OtpPage()));
                },
              ),
            ],
          ),
        ),

知道如何让按钮利用更多空间

【问题讨论】:

  • 我找到了一个解决方案here,它确实有效。

标签: flutter material-design flutter-layout


【解决方案1】:

您可以使用ButtonTheme 属性编辑按钮大小

Raised buttons have a minimum size of 88.0 by 36.0 which can be overridden with ButtonTheme.

其次,

您可以尝试用Expanded 小部件包装按钮

        Padding(
          padding: const EdgeInsets.all(8.0),
          child: ButtonBar(
            mainAxisSize: MainAxisSize.max,
            alignment: MainAxisAlignment.center,
            children: <Widget>[
              Expanded(
                child: RaisedButton(
                  child: Text('Save'),
                  onPressed: () {
                    Navigator.push(context,
                        MaterialPageRoute(builder: (context) => OtpPage()));
                  },
                ),
              ),
            ],
          ),
        ),

【讨论】:

  • 谢谢,我会试试尺寸,但扩展后的按钮栏儿童不起作用
  • 扩展小部件可以在行和列中使用
猜你喜欢
  • 2019-09-25
  • 2019-05-07
  • 1970-01-01
  • 1970-01-01
  • 2010-10-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-07
相关资源
最近更新 更多