Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have Circle ripple effect on an IconButton?

I would like to make a button with a circular ripple effect using an Icon, I've seen something online but I can't do it. It is not that straight forward like it should be. Trying with this code now.

InkWell(
                      onTap: () {},
                      splashColor: Colors.red,
                      highlightColor: Colors.white,
                      child: new Icon(
                        FontAwesomeIcons.chevronCircleUp,
                        size: 100,
                      ),
                    )

Another try was with this, but I cannot understand why those don't perfectly centers with each other.

Container(
                      margin: EdgeInsets.all(0.0),
                      height: 100.0,
                      width: 100.0,
                      child: new RaisedButton(
                          padding: EdgeInsets.all(0.0),
                          elevation: 100.0,
                          color: Colors.black,
                          highlightElevation: 0.0,
                          onPressed: () {},
                          splashColor: Colors.red,
                          highlightColor: Colors.red,
                          //shape: RoundedRectangleBorder e tutto il resto uguale
                          shape: CircleBorder(
                            side: BorderSide(color: Colors.black, width: 5),
                          ),
                          child: Icon(
                            FontAwesomeIcons.chevronCircleUp,
                            color: Colors.white.withOpacity(.8),
                            size: 80,
                          )),
                    ),

Thanks for the help

like image 687
Floris Marpepa Avatar asked Feb 28 '19 17:02

Floris Marpepa


People also ask

How do you get the ripple effect in flutter?

Flutter provides the InkWell widget to perform this effect. Create a ripple effect using the following steps: Create a widget that supports tap. Wrap it in an InkWell widget to manage tap callbacks and ripple animations.


1 Answers

I see that you'd like granular controll over the size of the ripple. I ended up using the code below.

Padding(
    padding: EdgeInsets.all(8.0),
    child: InkWell(
        customBorder: new CircleBorder(),
        onTap: () {},
        splashColor: Colors.red,
        child: new Icon(
            Icons.arrow_back,
            size: 24,
            color: Colors.black,
        ),
    ),
)

The InkWell effect renders a square, however using CircleBorder crops it to a circular shape.

By default the effect attempts to fill the space, so to modify the size I added padding on all sides, cropping the effect. If you are still having trouble with the ripple effect not rendering at all, wrapping your code in a Material() should fix most issues, or taking a look at the app theme.

like image 50
Jackson Moore Avatar answered Sep 27 '22 23:09

Jackson Moore