首页 文章

颤振 - 如何使用图像下方的图像和文本/图标的容器小部件

提问于
浏览
0

我在尝试在颤动的容器内创建图像和文本/图标时遇到了一些问题 . 我有什么far,我想在图像下包含三个行小部件,每行都有一个文本小部件或一个图标小部件,但每当我尝试这样做时,容器将只采用文本/图标小部件的形状和图像将消失 . 我在这种情况下使用了错误的小部件吗?我希望有类似于this的东西注意图片的底部 Headers ,日期和位置 .

我的代码:

class EventRow extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 150.0,
      margin: const EdgeInsets.symmetric(
        vertical: 16.0,
        horizontal: 24.0,
      ),
      child: new Stack(
        children: <Widget>[
          eventCardContent,
          userThumbnail,
        ],
      ),
    );
  }

  final userThumbnail = new Container(
    margin: EdgeInsets.symmetric(vertical: 16.0),
    alignment: FractionalOffset.centerLeft,
    child: CircleAvatar(
      backgroundImage: AssetImage("assets/images/letter_u.png"),
      backgroundColor: Colors.white,
      maxRadius: 40.0,
    ),
  );

  final eventCardContent = new Container(
    margin: new EdgeInsets.only(left: 46.0),
    decoration: new BoxDecoration(
      shape: BoxShape.rectangle,
      color: new Color(0xFFFFFFFF),
      borderRadius: new BorderRadius.circular(8.0),
      image: DecorationImage(
        image: AssetImage("assets/images/moon_pumpkin.jpeg"),
        fit: BoxFit.fill,
      ),
    ),
  );

1 回答

  • 0

    你需要用user包装userThumbnail容器并使用属性mainAxisSize:MainAxisSize.min来解决你的问题 .

    以下代码可以帮助您 .

    @override
    Widget build (BuildContext context) {
    return Scaffold(
      appBar: new AppBar(
        title: new Text("Csd"),
      ),
      body: Column(
        children: <Widget>[
          Container(
            height: 150.0,
            margin: const EdgeInsets.symmetric(
              vertical: 16.0,
              horizontal: 24.0,
            ),
            child: new Stack(
              children: <Widget>[
                eventCardContent,
                userThumbnail,
              ],
            ),
          ),
          new Column(
            children: <Widget>[
              Row(
                children: <Widget>[
                  new Column(
                    children: <Widget>[
                      Text("SEP"),
                      Text("30"),
                    ],
                  ),
                  Expanded(
                     child:new Column(
                       children: <Widget>[
                         new Text("title"),
                         new Text("Sub title"),
                         new Text("Second Sub Title"),
                       ],
                     )
                  )
                ],
              ),
    
            ],
          )
        ],
      ),
    );
    }
    

相关问题