【问题标题】:flutter Remove background color from Floating Action Button颤动从浮动操作按钮中删除背景颜色
【发布时间】:2021-04-19 05:16:38
【问题描述】:

我正在使用图像作为颤动浮动操作按钮的子项。我不需要任何背景颜色。 而且我需要使图像尺寸更大。我怎样才能做到这一点?请帮忙。

【问题讨论】:

    标签: android image flutter floating-action-button


    【解决方案1】:
    Colors.transparent
    

    将从任何接受颜色参数的小部件中删除颜色。请在您的 FloatingActionButton 中使用它,如下所示:

               FloatingActionButton(
                  elevation: 0.0,
                  child: new Icon(Icons.check),
                  backgroundColor: Colors.transparent,
                  onPressed: (){}
                )
    

    【讨论】:

      【解决方案2】:

      我认为对于您的情况,您也可以尝试这样的解决方法,

      floatingActionButton: GestureDetector(
              onTap: () {
                // Do Something
              },
              child: Container(
                decoration: BoxDecoration(
                  image: DecorationImage(
                      image: NetworkImage("https://www.dartpad.dev/dart-192.png")),
                  borderRadius: BorderRadius.circular(0.50),
                ),
                width: 50.0,
                height: 50.0,
              ),
            ),
      

      使用height 和width 值来获得所需的结果。您还可以将boxShadow 添加到Container 以看起来像实际的FAB。

      参考:https://api.flutter.dev/flutter/painting/BoxDecoration-class.html
      以及从资产中包含您的图像,请参阅https://api.flutter.dev/flutter/painting/DecorationImage-class.html

      希望这适合你的情况!

      【讨论】:

      【解决方案3】:

      只需这样做:

      FloatingActionButton(
          backgroundColor: Colors.transparent,
      )
      

      【讨论】:

      • 哇,它的 owsum 更多。等待给你更新。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-15
      • 1970-01-01
      • 2020-02-01
      • 2016-09-26
      • 1970-01-01
      • 2019-10-04
      • 2017-03-27
      相关资源
      最近更新 更多