10

Is it possible to set backgroundColor of FAB to gradient instead of plain color?

My button:

floatingActionButton: FloatingActionButton(
    backgroundColor: const Color(0xFFFF006E),
    child: const Icon(Icons.add, size: 40.0),
    onPressed: () {
        print('Start');
    },
),

4 Answers 4

24
floatingActionButton: FloatingActionButton(
  child: Container(
    width: 60,
    height: 60,
    child: Icon(
      Icons.add,
      size: 40,
    ),
    decoration: BoxDecoration(
      shape: BoxShape.circle,
      gradient: LinearGradient(colors: [Colors.red, Colors.blue])
    ),
  ),
  onPressed: () {},
)
Sign up to request clarification or add additional context in comments.

1 Comment

This can disable the ripple effect from the FAB's onPressed method
5

Use can use a Container with the Gradient you want

floatingActionButton: FloatingActionButton(
            child: Container(
              height: 60,
              width: 60,
              decoration: BoxDecoration(
                shape: BoxShape.circle, // circular shape
                gradient: LinearGradient(
                  colors: [
                    Colors.blueAccent,
                    Colors.red,
                  ],
                ),
              ),
              child: Icon(
                Icons.add,
                color: Colors.white,
              ),
            ),
          )

1 Comment

FYI this disables inkwell effect.
1

I found this solution. I don't need to set the height and width. Firstly I wrapped the floating action button with a container. Then I changed the background color of the floating action button to transparent.

Example code:

Container(
    decoration: BoxDecoration(
    gradient: LinearGradient(
        colors: [
        Colors.yellow,
        Colors.yellow.shade700,
        ],
    ),
    shape: BoxShape.circle,
    ),
    child: FloatingActionButton(
    onPressed: () {},
    backgroundColor: Colors.transparent,
    elevation: 0,
    child: Icon(Icons.home)
    ),
),

Comments

0

I Hope this will do ....

 FloatingActionButton(
    onPressed: () {},
      child: Container(
        height: 60,
        width: 60,
        decoration: BoxDecoration(
          shape: BoxShape.circle, 
          gradient: LinearGradient(
            colors: [
              Colors.teal,
              Colors.tealAcent
            ],
          ),
        ),
        child: Icon(
          Icons.add,
          color: Colors.white,
        ),
      ),
    )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.