【问题标题】:Unable to change image size in dart无法更改飞镖中的图像大小
【发布时间】:2020-01-03 13:27:27
【问题描述】:

我的图片无法调整大小。首先,我将背景放在容器小部件中。之后,我使用 Image.assets 将徽标图像放在中心小部件中。主要问题是图像的大小正在根据高度和宽度调整大小。目前,我正在使用 dart 语言在 Flutter 框架中进行编码。

我正在 Android Studio 中进行编码。

@override
  Widget build(BuildContext context) {
    return new MaterialApp(
      debugShowCheckedModeBanner: false,
      home: new Scaffold(
        body: new Stack(
          children: <Widget>[
            new Container(
              decoration: new BoxDecoration(
                  image: new DecorationImage(
                      image: new AssetImage("assets/imgs/home_bg.png"),
                      fit: BoxFit.cover,
                  )
              ),
            ),
            new Center(
              child: Image.asset("assets/imgs/home_logo.png",height: 300,width:300,),
            )
          ],
        ),
      ),
    );

没有显示错误消息。然后图像也没有调整大小。

【问题讨论】:

    标签: flutter dart


    【解决方案1】:
          body: Center(
            child: SizedBox(
              width: 100.0,
              height: 100.0,
              child: Image.network(
                  "https://th.thgim.com/opinion/op-ed/article22695424.ece/alternates/FREE_300/9thscience"),
            ),
          ))
    

    【讨论】:

    • 记得指定宽度和高度,否则不起作用。
    【解决方案2】:

    你可以像这样使用它-

    new Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        mainAxisSize: MainAxisSize.max,
        children: <Widget>[
        new Expanded(child: new Image.asset(
            "assets/imgs/home_logo.png",height: 300,width:300,
        ),
    
        ),
      ]
    )
    

    【讨论】:

    • 文本是什么(cover.name)??
    • 对不起,我删除了它
    • 哦...但它仍然没有调整大小
    【解决方案3】:
      new Container(
                            height: 20.0,
                            width: 20.0,
                            decoration: BoxDecoration(
                                shape: BoxShape.circle, color: Colors.red),
                            child: Image.asset(
                              'assets/Like@3x.png',
                            )),
    

    【讨论】:

    • @3x 是什么意思?
    【解决方案4】:

    您也可以尝试将图像包装在位于 Column 中的 Flexible 中,该列被包装在具有您需要的尺寸的容器中

    【讨论】:

    • 不幸的是,我目前无法访问我的电脑。也许我可以稍后添加它,对不起:/
    • 另一种解决方案似乎更顺畅
    • 哦...谢谢,但请分享代码,因为我是 Flutter 的初学者
    • 并且还使用灵活的小部件图像未显示在屏幕上
    • 是的,您必须再次将图像本身包装在容器中。如果我没记错的话,这对我来说很好用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-10
    • 1970-01-01
    • 1970-01-01
    • 2021-12-20
    • 2013-12-27
    相关资源
    最近更新 更多