传递容器的图像

问题描述 投票:0回答:1

我试图让它在颤动:

而我的实际结果是:

我的代码是这样的:

 new Container(
                  height: 150.0,
                  margin: const EdgeInsets.only(top: 16.0, bottom: 8.0),
                  child: new Stack(
                    children: <Widget>[
                      recantoCard,
                      recantoThumbnail,
                    ],
                  ),
                )
final recantoThumbnail = new Container(
  alignment: new FractionalOffset(0.0, 0.5),
  margin: const EdgeInsets.only(left: 5.0, top: 10),
  child: new Image(
    image: new AssetImage("assets/nossos_restaurantes.png"),
    height: 350.0,
  ),
);

final recantoCard = new Container(
  margin: const EdgeInsets.only(left: 0.0, right: 48.0),
  decoration: new BoxDecoration(
    color: Color(getColorHexFromStr("E5E6E8")),
    shape: BoxShape.rectangle,
  ),
  child: new Container(
    margin: const EdgeInsets.only(top: 10.0, left: 170.0),
    constraints: new BoxConstraints.expand(),
    child: new Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        new Text("text",
            style: TextStyle(
                color: Colors.black,
                fontFamily: 'Poppins',
                fontWeight: FontWeight.w600,
                fontSize: 20.0)),
        new Text("texto:",
            style: TextStyle(
                color: Colors.black,
                fontFamily: 'Poppins',
                fontWeight: FontWeight.w500,
                fontSize: 17.0)),
      ],
    ),
  ),
);

该图像是一个.png文件,我需要将其覆盖到容器和堆栈中,但图像始终保持在150高度容器中。我怎么能用图像覆盖容器?

image dart flutter
1个回答
1
投票

要使图像覆盖容器,必须使用Matrix4.translationValues(double x,double y,double z)类。

无论何时需要立交变换,都可以使用此类:Matrix4.translationValues(0.0,60,0.0),

Container(
            height: 150.0,
            color: Colors.red,
              child: Center(
                 child:Container(
                   height: 130.0,
                   width: 130.0,
                    transform: Matrix4.translationValues(0.0, 60, 0.0),

                   child: Image.asset('assets/image.jpg'),
                 )
              ),
          )

This image will the result of the above code

© www.soinside.com 2019 - 2024. All rights reserved.