English 中文(简体)
我的闪光清单中的形象赢得了永远的填充或掩盖。
原标题:Images in my flutter list wont ever fill or cover
  • 时间:2024-02-08 02:00:38
  •  标签:
  • flutter

Ive been struggling to get images to either fill or cover in a Flutter list and all be the same width and height. The images from a Wordpress json feed are all different sizes and aspect ratios. The images always are the same width with all the different code i ve tried but i cant seem to get them to be an even consistent height with each row in the list.

import  package:flutter/material.dart ;
import  data.dart ; // Import your Post model

class RecentPosts extends StatelessWidget {
  final List<Post> posts;

  const RecentPosts({Key? key, required this.posts}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    const double imageHeight = 100.0; // Fixed height for images
    const double imageWidth = 120.0; // Fixed width for images

    return ListView.builder(
      itemCount: posts.length,
      itemBuilder: (context, index) {
        final post = posts[index];

        return Card(
          clipBehavior: Clip.antiAlias,
          margin: const EdgeInsets.only(bottom: 16.0),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Image.network(
                post.imageUrl,
                width: imageWidth,
                height: imageHeight,
                fit: BoxFit.cover,
              ),
              Expanded(
                child: Padding(
                  padding: const EdgeInsets.all(10.0),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        post.title,
                        style: const TextStyle(
                          fontWeight: FontWeight.bold,
                          fontSize: 16.0,
                        ),
                        overflow: TextOverflow.ellipsis,
                        maxLines: 2,
                      ),
                      const SizedBox(height: 4.0),
                      Text(
                        post.excerpt,
                        style: TextStyle(
                          color: Colors.grey[600],
                          fontSize: 12.0,
                        ),
                        overflow: TextOverflow.ellipsis,
                        maxLines: 2,
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
        );
      },
    );
  }
}

Ive尝试了名单、电网和卡片,所有问题都是相同的。

“entergraph

问题回答

<代码>Image内的植被适当配置。 问题是,案文太大,因此推导了<代码>。 贺卡的高度高于固定的形象高度。 由于<代码>Image widget未能填满,因此,在图像之外还有额外空间。 罗高,不是因为图像不能符合<代码>Image

如果需要保持固定的形象高度,请将<代码>Card与<代码>SizedBox相加,并设定同样的高度:

SizedBox(
  height: imageHeight,
  child: Card(
    // ...
  ),
)

或者,你可以减少<代码>maxLines>,用于的植被,或减少体积。





相关问题
Flutter App cannot be installed on Android TV

I m building a Flutter app that should support Android TV and Mobile devices. Despite Google Play shows that it is supported, I cannot install app on my MiBox device. While trying to install it, both ...

Moving the icon button to the right causes rendering issues

I am trying to align the icon button to the right of the Text field, I tried the row which made the icon button not centered vertically and now I am trying out the Stack widget. Here is my code - ...

热门标签