【问题标题】:Flutter Card ListTile Image TextFlutter Card ListTile 图片文字
【发布时间】:2020-10-24 05:47:10
【问题描述】:

我对flutter应用程序的小部件有点新,我试图在卡片上做一个设计,这是不可能的,希望你能帮助我。

这是我的卡片小部件(我使用列表视图)。

Widget _cardSermon(BuildContext context, Data data) {
return Card(
  elevation: 3,
  margin: EdgeInsets.symmetric(vertical: 7), 
  child: ListTile(
    dense: true,
    leading: data.image != null ? Image.network("https://docs.google.com/uc?export=view&id="+data.image, height: 250, fit: BoxFit.fill) : Image.asset("assets/images/700_x_350.jpg"),
    title: new Text(
      data.title,
      style: new TextStyle(fontSize: 15.0, fontWeight: FontWeight.bold),
    ),
    subtitle: new Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          new Text(data.location,
              style: new TextStyle(
                  fontSize: 14.0, fontWeight: FontWeight.normal)),
          new Text('Population: ${data.date}',
              style: new TextStyle(
                  fontSize: 12.0, fontWeight: FontWeight.normal)),
        ]),
    onTap: () {
      print("taped");
    },
  )
);

这就是我的结果:

还不错,但这不是我所期望的,例如,我在不想要的图像上获得边距,并且无法在标题和 textx 之间添加边距。

这是我真正想要的:

真的希望你能帮助我,或者给出一些近似的设计,太难了,我还没有找到足够的帮助,谢谢大家。

【问题讨论】:

    标签: android ios image flutter card


    【解决方案1】:

    要实现您想要的,您应该将ListTile 更改为“自定义”布局Container,并在Card 中使用Row

    您可以使用它来帮助您开始:

            Container(
              height: 150,
              child: Card(
                color: Colors.orange,
                child: Row(
                  children: [
                    Expanded(
                      flex: 33,
                      child: Image.network(
                        'https://picsum.photos/250?image=9',
                      ),
                    ),
                    Expanded(
                      flex: 66,
                      child: Column(
                        children: [
                          Expanded(
                            flex: 50,
                            child: Center(child: Text('abc')),
                          ),
                          Expanded(flex: 25, child: Text('def')),
                          Expanded(flex: 25, child: Text('ghi')),
                        ],
                      ),
                    )
                  ],
                ),
              ),
            ),
    

    【讨论】:

    • 这里的问题是,图像被压缩在最大宽度设置,但好的想法是,图像没有被压缩,只是卡片取高度图像,也许这么dificilut?但是谢谢
    【解决方案2】:

    我认为您无法完全控制图块。
    您可以在此解决方案中添加尺寸。

    GestureDetector(
                child: Card(
                  elevation: 3,
                  color: Colors.black38,
                  child: Row(
                    children: [
                      SizedBox(
                        width: MediaQuery.of(context).size.width * 0.33,
                        child: Image.asset(
                          "assets/images/banane.jpg",
                          fit: BoxFit.fill,
                        ),
                      ),
                      Flexible(
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text(
                              "title",
                              style: new TextStyle(
                                  fontSize: 15.0, fontWeight: FontWeight.bold),
                            ),
                            new Text(
                              "location",
                              style: new TextStyle(
                                fontSize: 14.0,
                                fontWeight: FontWeight.normal,
                              ),
                            ),
                            Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Text(
                                  'Population: ${22 / 06 / 2020}',
                                  style: TextStyle(
                                    fontSize: 12.0,
                                    fontWeight: FontWeight.normal,
                                  ),
                                ),
                                Padding(
                                  padding:
                                      const EdgeInsets.symmetric(horizontal: 8.0),
                                  child: Icon(Icons.data_usage),
                                ),
                              ],
                            ),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
                onTap: () {},
              ),
     
    

    【讨论】:

    • 图像大于 33% 并且在设计上出现严重错误,您可以测试您的代码,您会看到它,但是谢谢
    • 我已经编辑了我的代码,它适用于你想要的各种尺寸。
    • 现在图像/图标出现错误:“引发了另一个异常:RenderFlex 在右侧溢出了 2.3 像素。”
    • 要解决这个错误,你只需要添加一些尺寸到它的其余部分我在flutter web上试过它工作得很好但是如果你不想要任何错误溢出你只需要添加尺寸到其余元素,以便从宽度屏幕中获得 100% 的附加值。如果您的图像占用 33%(0.33) 宽度,则其余部分应占用 67% (0.67) 如果您想要进行一些编辑,我会以非常干净的方式进行,但您需要在深夜等待。祝你好运
    猜你喜欢
    • 2020-10-03
    • 1970-01-01
    • 2019-11-25
    • 2020-03-19
    • 1970-01-01
    • 1970-01-01
    • 2021-04-26
    • 2017-11-17
    • 2021-02-22
    相关资源
    最近更新 更多