Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I can't set BorderRadius on Ink.image

Tags:

flutter

I can't seem to add BorderRadius to Ink.image image. I am able to add BorderRadius to all the other widges on top of the image (you can see that the container has BorderRadius but the image doesn't). What do I do? Do I need to reprogram this with another widget?

@override
Widget build(BuildContext context) {
  return Container(
    decoration: BoxDecoration(
      borderRadius: BorderRadius.circular(20),
    ),
    child: Ink.image(
      image: AssetImage(
        bgImage,
      ),
      fit: BoxFit.cover,
      child: InkWell(
        borderRadius: BorderRadius.circular(20),
        onTap: () {
          Navigator.of(context, rootNavigator: true).push(
            CupertinoPageRoute<bool>(
              fullscreenDialog: true,
              builder: (BuildContext context) => FP(),
            ),
          );
        },
        child: Center(
          child: Text(
            title,
            style: TextStyle(
                color: Colors.white,
                fontSize: 30,
                fontWeight: FontWeight.bold),
          ),
        ),
      ),
    ),
  );
}

You can see how there is a barely but visible border radius. I just need the image to have it as well.

like image 516
Victor Shin Avatar asked Oct 25 '25 09:10

Victor Shin


2 Answers

Use regular Ink with a decoration.borderRadius property.

Here is your updated code

Container(
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(20),
      ),
      child: Ink(
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(20),
          image: DecorationImage(
            image: AssetImage(
              bgImage,
            ),
            fit: BoxFit.cover,
          ),
        ),
        child: InkWell(
          borderRadius: BorderRadius.circular(20),
          onTap: () {
            Navigator.of(context, rootNavigator: true).push(
              CupertinoPageRoute<bool>(
                fullscreenDialog: true,
                builder: (BuildContext context) => FP(),
              ),
            );
          },
          child: Center(
            child: Text(
              title,
              style: TextStyle(
                  color: Colors.white,
                  fontSize: 30,
                  fontWeight: FontWeight.bold),
            ),
          ),
        ),
      ),
    );
like image 80
Hemal Moradiya Avatar answered Oct 27 '25 22:10

Hemal Moradiya


Wrap your Ink.image with a Material widget and then wrap the Material with a ClipRRect widget and set the borderRadius.

For example:

ClipRRect(
  borderRadius: BorderRadius.circular(16),
  child: Material(
    child: Ink.image(
      image: const AssetImage('image.png'),
      child: InkWell(
        onTap: () {},
      ),
    ),
  ),
),

This answer inspired by this comment in GitHub.

like image 41
Moaz El-sawaf Avatar answered Oct 27 '25 22:10

Moaz El-sawaf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!