I have created a custom widget for Rounded Image widget, here i want to apply image size to 50% of its parent..
This widget can be called in gridview.builder or inside any other widget like sizedbox..
I just want image size half to main container size…
class RoundedImage extends StatelessWidget {
const RoundedImage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.transparent,
border: Border.all(color: Colors.grey,width: 1),
borderRadius: BorderRadius.circular(20)
),
child: ClipRRect(
borderRadius: BorderRadius.circular(20),
child: Image.asset('lib/assets/xyz.jpeg',fit: BoxFit.cover,)),
);
}
}
2
Answers
A way to do it is by using FractionallySizedBox as follows:
I wanted the same when i was creating app.. here is the custom widget that might help you, and it will square and u may adjust height width by changing logic…and remove unnecessory Layout builder if you dont want…
two layout builders has been used…First one for parent and second one for child…..