flutter 从浮动操作按钮中删除背景颜色

flutter Remove background color from Floating Action Button

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

只需这样做:

FloatingActionButton(
    backgroundColor: Colors.transparent,
)

编辑: 我的回答只是一种解决方法。 backgroundColor: Colors.transparent一切顺利

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

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,
        ),
      ),

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

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

希望适合你的情况!

Colors.transparent

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

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