Mircea
Mircea

Reputation: 1999

Flutter Container BoxShadow doesn't show

Here it's my code in this moment:

ClipRRect(
  borderRadius: BorderRadius.circular(11),
  child: Container(
    decoration: BoxDecoration(
      gradient: LinearGradient(
        begin: FractionalOffset.bottomLeft,
        end: FractionalOffset.topRight,
        colors: <Color>[Colors.purple, AppBaseColors.orange],
      ),
      boxShadow: [BoxShadow(color: Colors.yellow)]
    ),
    child: Material(
      child: InkWell(
        onTap: () {
          print("tapped");
        },
        child: Container(
          width: ButtonTheme.of(context).minWidth,
          height: ButtonTheme.of(context).height,
          child: Center(
            child: Text(
              "log in",
              style: TextStyle(
                  color: Colors.white, fontWeight: FontWeight.bold),
            ),
          ),
        ),
      ),
      color: Colors.transparent,
    ),
  ),
),

WHAT HAVE I TRIED:

Any idea what I did wrong?

Upvotes: 6

Views: 11505

Answers (2)

X09
X09

Reputation: 3956

I fixed mine by removing the clipBehavior or setting it to Clip.none.

Upvotes: 0

diegoveloper
diegoveloper

Reputation: 103451

You need to do these changes:

  • remove the ClipRRect widget.
  • add borderRadius inside BoxDecoration.
  • add an Offset to your BoxShadow.

    Container(
              decoration: BoxDecoration(
                  color: Colors.blue,
                  gradient: LinearGradient(
                    begin: FractionalOffset.bottomLeft,
                    end: FractionalOffset.topRight,
                    colors: <Color>[Colors.purple, Colors.orange],
                  ),
                  borderRadius: BorderRadius.circular(11),
                  boxShadow: [
                    BoxShadow(color: Colors.yellow, offset: Offset(5.0, 5.0))
                  ]),
              child: Material(
                borderRadius: BorderRadius.circular(11),
                clipBehavior: Clip.hardEdge,
                child: InkWell(
                  onTap: () {
                    print("tapped");
                  },
                  child: Container(
                    width: ButtonTheme.of(context).minWidth,
                    height: ButtonTheme.of(context).height,
                    child: Center(
                      child: Text(
                        "log in",
                        style: TextStyle(
                            color: Colors.white, fontWeight: FontWeight.bold),
                      ),
                    ),
                  ),
                ),
                color: Colors.transparent,
              ),
            ),
    

Upvotes: 17

Related Questions