首页 > 解决方案 > 在 RaisedButton 内放置一个 CircularProgressIndicator 保持大小

问题描述

我想将 aCircularProgressIndicator放在a 内RaisedButton,但是当我这样做时, aCircularProgressIndicator不适合按钮并伸出它。

我想缩小CircularProgressIndicator,使其适合RaisedButton,我知道我可以使用 aSizedBox但我希望它是自动的,而不是我给它我想要的大小。我试过FittedBox了,但它的所有选项都没有任何区别。

这是我的按钮代码:

RaisedButton(
    onPressed: () => print('hi'),
    shape: StadiumBorder(),
    color: Theme.of(context).primaryColor,
    child: Row(
      children: <Widget>[       
      Padding(
          padding: const EdgeInsets.only(right: 12, top: 6, bottom: 6),
          child: CircularProgressIndicator(
            backgroundColor: Colors.white,
            strokeWidth: 2,
          ),
        ),        
        Text('Loading'),
      ],
    ),
),

这就是它的样子:

在此处输入图像描述

当我添加Padding它时,按钮会变大:

在此处输入图像描述

有没有办法自动实现这一点?


编辑:

为了清楚起见,我想要的最终效果是:

用户按下按钮之前和之后:

在此处输入图像描述 在此处输入图像描述

我希望高度自动保持不变,而SizedBox.

标签: flutterflutter-layout

解决方案


查看CircularProgressIndicator源代码,我可以发现硬编码的最小尺寸为 36.0 高度/宽度,因此无法自动变小。


推荐阅读