Flutter 中的 Image 组件 如何加载网络图片和本地图片

本文介绍了Flutter项目中如何使用Image组件加载本地和网络图片,并讲解了图片的自动适配机制。在项目的image文件夹下,系统会根据设备的像素密度自动选择合适的图片资源。同时,提到了两种实现图片圆角的方法:在Container组件中设置圆角或使用ClipOval组件。此外,还提及了Image组件的一些关键属性,如src、scale、fit等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

如下,直接上代码说明:

mian(){

    runApp(MyApp());

}

 

class MyApp extends StatelessWidget {

      @override

     Widget build(BuildContext context) {

        return Center(

             child:image.asset();//本地图片

             child:image.network();//网络图片

        );

     }

}

注意:在fultter项目中,我们在项目的根目录中新建一个 image 文件夹,将原图放在其中,然后再建立imagex2,imagex3文件夹,将对应的@2xhe @3x图片放入其中.

在项目中我们直接 import image 这个文件夹,里面的图片直接访问 原图,系统就会自动适配2倍和3倍图.

关于Image组件属性和用法:

String src, {

Key? key,

double scale = 1.0,

this.frameBuilder,

this.loadingBuilder,

this.errorBuilder,

this.semanticLabel,

this.excludeFromSemantics = false,

this.width,

this.height,

this.color,

this.colorBlendMode,

this.fit,

this.alignment = Alignment.center,

this.repeat = ImageRepeat.noRepeat,

this.centerSlice,

this.matchTextDirection = false,

this.gaplessPlayback = false,

this.filterQuality = FilterQuality.low,

this.isAntiAlias = false,

Map<String, String>? headers,

int? cacheWidth,

int? cacheHeight,

 

关于image圆角思路.

1:在父级组件中进行圆角设置,如在Container组件中属性decoration中设置圆角,然后把属性image: DecorationImage设置成图片显示

2:使用ClipOval组件作为父级组件,自动适应圆角.

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值