Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: Image overflow the container

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)),
                  )),
              ),
            ],
          ),
        ),
      ),
    );
  }
}  

Preview

like image 526
Hung Nguyen Avatar asked Oct 13 '18 19:10

Hung Nguyen


People also ask

How do you fix a flutter overflow in a container?

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.

How do you make a container take full width flutter?

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.


1 Answers

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

like image 146
Raouf Rahiche Avatar answered Sep 20 '22 17:09

Raouf Rahiche