如何解决这个问题?我没有得到字幕文字

时间:2019-03-28 06:16:37

标签: flutter

See in the categories below catalogues 我无法在图片下方显示字幕

我所做的粘贴在下面。我想查看图像的标题,并且已经提供了路径并将其存储在图像的ImageLocation变量和字幕文本的ImageCaption变量中。下面是该页面的完整代码,并且在main.dart中调用了Horizo​​ntalHorizo​​n类

   import 'package:flutter/material.dart';

class HorizontalList extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 80.0,
      child:ListView(
        scrollDirection: Axis.horizontal,
        children: <Widget>[
          Category(
            imageLocation: 'images/cats/tshirt.png',
            imageCaption: 'shirt',
          ),

          Category(
            imageLocation: 'images/cats/jeans.png',
            imageCaption: 'jeans',
          ),

          Category(
            imageLocation: 'images/cats/dress.png',
            imageCaption: 'dress',
          ),

          Category(
            imageLocation: 'images/cats/formal.png',
            imageCaption: 'formal',
          ),

          Category(
            imageLocation: 'images/cats/shoe.png',
            imageCaption: 'shoe',
          ),

          Category(
            imageLocation: 'images/cats/informal.png',
            imageCaption: 'informal',
          ),

          Category(
            imageLocation: 'images/cats/accessories.png',
            imageCaption: 'accessory',
          ),
        ],
      ),
    );
  }
}

class Category extends StatelessWidget {
  final String imageLocation;
  final String imageCaption;

  Category({
    this.imageLocation,
    this.imageCaption
  });

  @override
  Widget build(BuildContext context) {
    return Padding(padding: const EdgeInsets.all(2.0),
      child: InkWell(
        onTap: (){},
        child: Container(
          width: 100.0,
          child: new ListTile(
            title: Image.asset(
              imageLocation,
              width: 100.0,
              height: 80.0
            ),
            subtitle: Container(
              alignment: Alignment.topCenter, 
              child: Text(imageCaption, style: new TextStyle(fontSize: 12.0),)
            ),  
          ),
        ),  
      ),
    );
  }
}

1 个答案:

答案 0 :(得分:0)

您只需要删除height: 80.0,,因为它会修剪您的卡片

因此您的代码将是

  import 'package:flutter/material.dart';

class HorizontalList extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      child:ListView(
        scrollDirection: Axis.horizontal,
        children: <Widget>[
          Category(
            imageLocation: 'images/cats/tshirt.png',
            imageCaption: 'shirt',
          ),

          Category(
            imageLocation: 'images/cats/jeans.png',
            imageCaption: 'jeans',
          ),

          Category(
            imageLocation: 'images/cats/dress.png',
            imageCaption: 'dress',
          ),

          Category(
            imageLocation: 'images/cats/formal.png',
            imageCaption: 'formal',
          ),

          Category(
            imageLocation: 'images/cats/shoe.png',
            imageCaption: 'shoe',
          ),

          Category(
            imageLocation: 'images/cats/informal.png',
            imageCaption: 'informal',
          ),

          Category(
            imageLocation: 'images/cats/accessories.png',
            imageCaption: 'accessory',
          ),
        ],
      ),
    );
  }
}

class Category extends StatelessWidget {
  final String imageLocation;
  final String imageCaption;

  Category({
    this.imageLocation,
    this.imageCaption
  });

  @override
  Widget build(BuildContext context) {
    return Padding(padding: const EdgeInsets.all(2.0),
      child: InkWell(
        onTap: (){},
        child: Container(
          width: 100.0,
          child: new ListTile(
            title: Image.asset(
              imageLocation,
              width: 100.0,
              height: 80.0
            ),
            subtitle: Container(
              alignment: Alignment.topCenter, 
              child: Text(imageCaption, style: new TextStyle(fontSize: 12.0),)
            ),  
          ),
        ),  
      ),
    );
  }
}