I'm making a list of event information in Flutter by using Card for each event. The leading of each card is a related to the event.
I want to make my Card to be rounded corner rectangle, but when I put the image inside the children of Row inside child of Card, the corner of the image is not rounded.
My Card class:
import 'package:flutter/material.dart';
class SmallEventCard extends StatefulWidget {
final imageURL;
final title;
final time;
final place;
SmallEventCard({this.imageURL, this.title, this.time, this.place});
@override
_SmallEventCardState createState() => _SmallEventCardState();
}
class _SmallEventCardState extends State<SmallEventCard> {
bool isFavorite;
@override
void initState() {
// TODO: implement initState
super.initState();
isFavorite = false;
}
@override
Widget build(BuildContext context) {
final screen = MediaQuery.of(context).size;
return Material(
child: SizedBox(
height: screen.height / 7,
child: Card(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),
child: Row(
children: <Widget>[
AspectRatio(
aspectRatio: 4 / 3,
child: Image.network(widget.imageURL,
fit: BoxFit.fitHeight,
),
),
SizedBox(
width: 10.0,
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(widget.title,
style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold),maxLines: 2, overflow: TextOverflow.clip,
),
SizedBox(height: 5.0,),
Text(widget.time.toString(),
overflow: TextOverflow.clip,
),
SizedBox(height: 5.0,),
Text(widget.place,
overflow: TextOverflow.clip,
),
],
),
),
SizedBox(
width: 50.0,
child: Align(
alignment: Alignment.centerRight,
child: Padding(
padding: const EdgeInsets.all(10.0),
child: IconButton(
onPressed: () {},
icon: Icon(Icons.favorite_border)),
)),
),
],
),
),
),
);
}
}
Solution : The solution to resolve this overflow error is to make your entire widget or in our case the Column scrollable. We can do that by wrapping our Column inside a SingleChildScrollView. Also, wrap the SingleChildScrollView with Center so that the entire UI is centered.
If you are building an app for the first time and wondered how to set up a full-width Container with Flutter, then these code examples are for you. here, we are using double. infinity assigned as a value to the width property of the Container widget. This will make our container spread through full-screen horizontally.
the Card
widget has it's own clipping behavior so you can just to set the clipBehavior
property to Clip.antiAlias
so the content outside the card will be clipped
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With