简体   繁体   English

如何制作径向渐变浮动动作按钮

[英]How to make a radial gradient floating action button

Is there any way to set the floating action buttons color as a radial gradient in flutter?有没有办法在 flutter 中将浮动操作按钮颜色设置为径向渐变? Something like below:如下所示:

在此处输入图像描述

Set a container as the child of that FAB and assign a gradient to the container.将一个容器设置为该 FAB 的子级,并为该容器分配一个渐变。

FloatingActionButton(
   onPressed: () {},
   tooltip: 'Cool FAB',
   child: Container(
      decoration: BoxDecoration(
         shape: BoxShape.circle,
         gradient: RadialGradient(
            center: const Alignment(0.0, 0.0),
            radius: 0.5,
            colors: [ Color(0xFF0187D0), Color(0xFF01579C),],
         ),
      ),
   ),
),

It will look like:它看起来像:

渐变FAB

EDIT:编辑:

For adding icon, you have to specify a size to your container and set the icon as it's child (I've used the FAB default size of 56x56).要添加图标,您必须为容器指定大小并将图标设置为子图标(我使用 FAB 默认大小为 56x56)。

FloatingActionButton(
   onPressed: () {},
   tooltip: 'Cool FAB',
   child: Container(
      width: 56,
      height: 56,
      child: Icon(Icons.settings),
      decoration: BoxDecoration(
         shape: BoxShape.circle,
         gradient: RadialGradient(
            center: const Alignment(0.0, 0.0),
            radius: 0.5,
            colors: [ Color(0xFF0187D0), Color(0xFF01579C),],
         ),
      ),
   ),
),

And now it will look like:现在它看起来像:

带有图标的 FAB

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM