我正在使用Ffltter,并try 将图像的纵横比从4:3更改为16:9.我try 使用AspectRatio小部件,也try 使用FittedBox,但图像仍保持4:3

我已经try 使用AspectRatio,将Image上的Fitprops 更改为Cover、Fit和Conclude

Card(elevation: 3.0, child: Column(
children: <Widget>[Container(child:
AspectRatio(aspectRatio: 16.0 / 9.0, child: FittedBox(fit: 
BoxFit.contain,
child: Image(image: AssetImage('images/maggie.jpg')),),)
                                   )],

推荐答案

你需要使用BoxFit.fill才能看到效果,BoxFit.cover显示的效果与图像裁剪后的效果相同.而且你也不需要FittedBox.

Card(
  elevation: 3.0,
  child: Column(
    children: <Widget>[
      Container(
        child: AspectRatio(
          aspectRatio: 16 / 9,
          child: Image(
            image: AssetImage('images/maggie.jpg'),
            fit: BoxFit.fill, // use this
          ),
        ),
      )
    ],
  ),
)

Dart相关问答推荐

为什么在穷举switch 表达式中需要显式向下转换?

基本数学函数的DART源代码

Dart 可空记录与模式匹配:(String, int)?类型的匹配值无法分配给所需类型(Object?, Object?)

从扩展类访问抽象类属性

带有字符串键的 Dart Map,与忽略大小写进行比较

在 Dart 中处理字节数组时,使用 Uint8List 优于 List 有什么优势?

ProcessException:进程C:\..\myapp\android\gradlew.bat异常退出:

Stack inside Stack in flutter

Dart / Flutter 错误:没有为类Logger定义toStringDeep

更改底片的灰色覆盖背景

找不到正确的提供程序-Flutter

Flutter Drawer Widget - 更改 Scaffold.body 内容

如何在Dart中处理JSON

如何对map值进行排序?

在我的 angular-cli 元素中从 node-sass 切换到 dart sass

如何在 Dart 中扩展列表?

Dart 中的外部是什么意思?

在 Dart 中没有换行符的 print()?

如何使用 Dart 构建枚举?

从函数返回多个值