【问题标题】:How to set OutlineButton width > child width and the border expand to all available space?如何设置 OutlineButton 宽度 > 子宽度和边框扩展到所有可用空间?
【发布时间】:2018-07-26 03:01:10
【问题描述】:

我有一个这样的自定义按钮:

class ControlButton extends StatelessWidget {
  final String text;
  final void Function() onPressed;
  final double width;
  final double height;

  ControlButton({
    @required this.text,
    @required this.onPressed,
    this.width = 90.0,
    this.height = 40.0,
  });

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: width,
      height: height,
      child: OutlineButton(
        borderSide: BorderSide(color: _orangeColor),
        onPressed: onPressed,
        child: Text(
          text,
          style: TextStyle(color: _orangeColor),
        ),
      ),
    );
  }
}

并像这样使用这个按钮:

          ControlButton(
            text: 'Hold on',
            onPressed: () {},
          ),

当我尝试设置宽度子宽度时,按钮两侧有未使用的空格,当我设置宽度=子宽度时,边框仍然保持不变。

有什么方法可以设置宽度 > 子宽度并且按钮边框扩展到所有可用空间?

【问题讨论】:

  • 我最近修复了一个错误,该错误会阻止按钮尽可能宽,这可能目前仅在 master 分支中。
  • @JonahWilliams 谢谢,我正在使用开发频道。我将尝试切换到 master 以查看是否已修复。
  • 哇,它按预期工作。谢谢你。 ^^

标签: dart flutter


【解决方案1】:

这实际上是一个错误,任何遇到此问题的人请使用flutter> v0.5.8-pre.141​​切换到主频道

【讨论】:

    猜你喜欢
    • 2022-12-04
    • 1970-01-01
    • 2021-10-20
    • 1970-01-01
    • 2013-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多