如何更改FloatingActionButton的大小?

113

我想在Flutter中为FloatingActionButton设置一个大小,我想设置width/height,也就是说,让按钮变大,我一直在寻找一个圆形的按钮,但是我找到的唯一一个是这个,所以我开始使用它,但我需要它再大一点。

15个回答

1
您可以使用 extendedPadding。这对我很有效。
floatingActionButton: FloatingActionButton.extended(
    onPressed: () {
      // Add your onPressed code here!
    },
    extendedPadding:
        const EdgeInsets.only(left: 100, right: 100, top: 20, bottom: 20),
    label: const Text('Approve'),
    icon: const Icon(Icons.thumb_up),
    backgroundColor: Colors.pink,
  ),

0
请在主题中使用以下选项。
floatingActionButtonTheme: const FloatingActionButtonThemeData(
  sizeConstraints: BoxConstraints.expand(
    width: 60,
    height: 60,
  ),
)

0
我使用了Expanded来扩大按钮在行或列中的大小。
    content: Column(
      mainAxisSize: MainAxisSize.min,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        Row(children: [
          Expanded(
              child: FloatingActionButton.extended(

-1

2
虽然这段代码可能解决了问题,但包括解释如何以及为什么解决该问题将真正有助于提高您的帖子质量,并可能导致更多人点赞。请记住,您正在回答未来读者的问题,而不仅是现在提问的人。请[编辑]您的答案以添加解释并指示适用的限制和假设。请注意,解释的链接是受欢迎的,但此处的摘要更受欢迎。 - Yunnosch
我试图帮助您进行格式设置,但不确定第一行和最后一行。请使用 https://stackoverflow.com/editing-help 进行双重检查。 - Yunnosch

-1

试试这个:

floatingActionButton: Container(
    height: 50.0,
    width: MediaQuery.of(context).size.width * 0.92,
    decoration: BoxDecoration(
        color: Colors.blue, borderRadius: BorderRadius.circular(30)),
    child: Center(
      child: Text(
        'SAVE',
        textAlign: TextAlign.center,
        style: TextStyle(
            fontWeight: FontWeight.w700,
            fontSize: 16.0,
            color: whiteTextColor),
      ),
    ),
  ),

1
欢迎来到Stack Overflow,并感谢您为问题提供答案。您是否可以编辑您的答案并包含代码解释?这将有助于未来的读者更好地理解正在发生的事情,特别是那些对该语言不熟悉且难以理解概念的社区成员。当社区已经验证了一个答案时,这尤其重要。在什么条件下可能会优先考虑您的方法?您是否利用了新的功能? - Jeremy Caney
你的回答可以通过提供更多支持信息来改进。请编辑以添加进一步的细节,例如引用或文档,以便他人可以确认你的答案是正确的。您可以在帮助中心找到有关如何编写良好答案的更多信息。 - Community

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接