Grid view image View difference Problem in Flutter?


I am showing images on gridview but i have a problem. I want to make the image’s height and width equal.

This is the picture and I want to make image on the right to the have same width and height like the left one.Or at least put a white cover to missing part.

enter image description here
This is my code:

child: Consumer<Images>(
                        builder: (ctx, titles, ch) => GridView.builder(
                            physics: ScrollPhysics(),
                            itemCount: titles.items.length,
                              crossAxisCount: getSize(_currentSliderValue),
                              mainAxisSpacing: 50,
                              childAspectRatio: 115/162.05,
                              crossAxisSpacing: 5,
                            itemBuilder: (ctx, index) {


                              return GestureDetector(
                                onTap: () => add(titles.items[index].image),
                                child: selected.contains(titles
                                    .toString()) ?

                                Container(child: selectedimage(titles.items[index].image)) :

                                  Container(child:  nonselected(titles.items[index].image))


And this is my widget function:

Widget selectedimage(image) {
    return Stack(children: <Widget>[
      Image.file(image, fit: BoxFit.cover),
        right: 12,
        bottom: 10,
        child: Image.asset("assets/images/selected.png", width: 26, height: 26),

  Widget nonselected(image) {
    return Stack(children: <Widget>[
      Image.file(image, fit: BoxFit.cover),

selectedimage function is to put check icon when the image is selected.


Instead of use Image.file or Image.asset as a child you can try using AssetImage or FileImage inside Container decoration like :

  decoration: BoxDecoration(
    image: DecorationImage(
      image: FileImage(image),
      fit: BoxFit.cover,

Answered By – Kisame Hoshigaki

Answer Checked By – Marilyn (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *