I use the code below, how do I make the image appear in the boxDecoration that follows the borderRadius pattern?
Flexible(
child: GestureDetector(
onTap: () {
print("Menu 1");
},
child: Container(
height: 150,
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white
),
child: Column(
children: [
Image.asset(
"assets/images/new_images/korean_food.jpg",
fit: BoxFit.cover,
),
SizedBox(height: 10,),
Text(
'Paket Korea',
style: TextStyle(
fontFamily: "Khand",
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
Text(
'Rp 30.000',
style: TextStyle(
fontFamily: "Khand",
fontSize: 14,
color: Color.fromRGBO(2, 161, 113, 1),
fontWeight: FontWeight.w300,
),
),
],
),
),
),
),
this is what the design should look like following the borderRadius image
and this is the result of the code after I run it
can anyone help me solve this problem?
2
Answers
New Answer: use
clipBehaviour
container property:Old Answer: remove
borderRadius
from Container and Wrap the Container withClipRRect
Widget:To achieve the desired design where the image follows the border radius pattern of the Container, you can use a combination of ClipRRect and BoxDecoration. Here’s how you can modify your code:
In this modification, I wrapped the Image.asset widget with a ClipRRect widget, which clips the image to the specified border radius. The ClipRRect uses the same BorderRadius.circular(10) as the Container’s BoxDecoration, ensuring that the image follows the rounded corners of the container.
You may need to adjust the padding or layout as per your design requirements.