Flutter: 浮动操作按钮阴影

10

您能否或者有什么方法可以改变FloatingActionButton.extended或其他悬浮按钮所产生的阴影颜色?


目前还不行。考虑通过分叉源代码或从较低级别的小部件组合(如“Material”)来创建自己的“FloatingButton”,以适应您的需求。 - Rémi Rousselet
3个回答

12
您可以尝试这种方法:

在此输入图片描述

floatingActionButton: FloatingActionButton(
      onPressed: () {},
      backgroundColor: Colors.red,
      elevation: 0,
      child: Container(
        decoration: BoxDecoration(
          color: Colors.transparent,
          borderRadius: BorderRadius.all(
            Radius.circular(100),
          ),
          boxShadow: [
            BoxShadow(
              color: Colors.purple.withOpacity(0.3),
              spreadRadius: 7,
              blurRadius: 7,
              offset: Offset(3, 5),
            ),
          ],
        ),
      ),
    ),

0
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
    floatingActionButton: Container(
      height: 70,
      width: 70,
     margin: const EdgeInsets.only(bottom: 10.0),
      decoration: BoxDecoration(
        color: Colors.transparent,
        borderRadius: const BorderRadius.all(
          Radius.circular(100),
        ),
        boxShadow: [
          BoxShadow(
            color: MyColors.myWhite.withOpacity(0.3),
            spreadRadius: 6,
            blurRadius: 6,
            offset: const Offset(0.5, 0.5),
          ),
        ],
      ),
      child: FittedBox(
        child: FloatingActionButton(
            onPressed: (){},
          backgroundColor: MyColors.myGreen,
          elevation: 10,
            child: const Icon(Icons.add,
            color: MyColors.myWhite,
              size: 18,
              shadows: [Shadow(
                color: MyColors.myWhite,
                offset: Offset(0.2, 0.5),
                blurRadius: 5.0,
              )],
            ),
          ),
        ),
  ),

0
floatingActionButton: FloatingActionButton(
        onPressed: (){},
      backgroundColor: Color(0xf0004451),
      elevation: 10,

      child: Container(
        padding: const EdgeInsets.all(14.0),
        decoration: BoxDecoration(
          color: Colors.transparent,
          borderRadius: BorderRadius.all(
            Radius.circular(60),
          ),
          boxShadow: [
            BoxShadow(
              color: Color(0xffE1E8EB).withOpacity(0.35),
              spreadRadius: 8,
              blurRadius: 8,
              offset: const Offset(1, 1),
            ),
          ],
        ),
        child: const Icon(Icons.add,
        color: Color(0xffE1E8EB),
          size: 18,
          shadows: [Shadow(
            color: Color(0xffE1E8EB),
            offset: Offset(0.2, 0.5),
            blurRadius: 5.0,
          )],
        ),
      ),
    ),

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