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

Flutter 如何解决这个问题?我没有收到字幕文本,flutter,Flutter,我无法在图像下方显示字幕 我所做的事贴在下面。我想查看图像的标题,路径已经提供并存储在图像的ImageLocation变量和字幕文本的ImageCaption变量中。下面是页面的完整代码,在main.dart中调用了类HorizontalList import 'package:flutter/material.dart'; class HorizontalList extends StatelessWidget { @override Widget build(BuildCon

我无法在图像下方显示字幕

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

   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),)
            ),  
          ),
        ),  
      ),
    );
  }
}
导入“包装:颤振/材料.省道”;
类HorizontalList扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回容器(
身高:80.0,
子:ListView(
滚动方向:轴水平,
儿童:[
类别(
imageLocation:'images/cats/tshirt.png',
图片说明:“衬衫”,
),
类别(
imageLocation:'images/cats/jeans.png',
图片说明:“牛仔裤”,
),
类别(
imageLocation:'images/cats/dress.png',
图片说明:“连衣裙”,
),
类别(
imageLocation:'images/cats/formal.png',
图片说明:“正式”,
),
类别(
imageLocation:'images/cats/shoe.png',
图片说明:“鞋子”,
),
类别(
imageLocation:'images/cats/unformal.png',
图片说明:“非正式”,
),
类别(
imageLocation:'images/cats/accessories.png',
图片说明:“附件”,
),
],
),
);
}
}
类类别扩展了无状态小部件{
最终字符串位置;
最终字符串图像标题;
类别({
这个位置,
这是imageCaption
});
@凌驾
小部件构建(构建上下文){
返回填充(填充:const EdgeInsets.all(2.0),
孩子:InkWell(
onTap:(){},
子:容器(
宽度:100.0,
孩子:新的ListTile(
标题:Image.asset(
图像定位,
宽度:100.0,
身高:80.0
),
字幕:集装箱(
对齐:alignment.topCenter,
子项:文本(图像标题,样式:新文本样式(fontSize:12.0),)
),  
),
),  
),
);
}
}

您只需删除高度为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),)
            ),  
          ),
        ),  
      ),
    );
  }
}
导入“包装:颤振/材料.省道”;
类HorizontalList扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回容器(
子:ListView(
滚动方向:轴水平,
儿童:[
类别(
imageLocation:'images/cats/tshirt.png',
图片说明:“衬衫”,
),
类别(
imageLocation:'images/cats/jeans.png',
图片说明:“牛仔裤”,
),
类别(
imageLocation:'images/cats/dress.png',
图片说明:“连衣裙”,
),
类别(
imageLocation:'images/cats/formal.png',
图片说明:“正式”,
),
类别(
imageLocation:'images/cats/shoe.png',
图片说明:“鞋子”,
),
类别(
imageLocation:'images/cats/unformal.png',
图片说明:“非正式”,
),
类别(
imageLocation:'images/cats/accessories.png',
图片说明:“附件”,
),
],
),
);
}
}
类类别扩展了无状态小部件{
最终字符串位置;
最终字符串图像标题;
类别({
这个位置,
这是imageCaption
});
@凌驾
小部件构建(构建上下文){
返回填充(填充:const EdgeInsets.all(2.0),
孩子:InkWell(
onTap:(){},
子:容器(
宽度:100.0,
孩子:新的ListTile(
标题:Image.asset(
图像定位,
宽度:100.0,
身高:80.0
),
字幕:集装箱(
对齐:alignment.topCenter,
子项:文本(图像标题,样式:新文本样式(fontSize:12.0),)
),  
),
),  
),
);
}
}

您只需删除高度为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),)
            ),  
          ),
        ),  
      ),
    );
  }
}
导入“包装:颤振/材料.省道”;
类HorizontalList扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回容器(
子:ListView(
滚动方向:轴水平,
儿童:[
类别(
imageLocation:'images/cats/tshirt.png',
图片说明:“衬衫”,
),
类别(
imageLocation:'images/cats/jeans.png',
图片说明:“牛仔裤”,
),
类别(
imageLocation:'images/cats/dress.png',
图片说明:“连衣裙”,
),
类别(
imageLocation:'images/cats/formal.png',
图片说明:“正式”,
),
类别(
imageLocation:'images/cats/shoe.png',
图片说明:“鞋子”,
),
类别(
imageLocation:'images/cats/unformal.png',
图片说明:“非正式”,
),
类别(
imageLocation:'images/cats/accessories.png',
图片说明:“附件”,
),
],
),
);
}
}
类类别扩展了无状态小部件{
最终字符串位置;
最终字符串图像标题;
类别({
这个位置,
这是imageCaption
});
@凌驾
小部件构建(构建上下文){
返回填充(填充:const EdgeInsets.all(2.0),
孩子:InkWell(
onTap:(){},
子:容器(
宽度:100.0,