flutter图片识别_Flutter Widget:实例讲解图片组件Image、Icon、ImageIcon

本文详细介绍了Flutter中的图片组件,包括Image的属性如image、width、height、fit、color等,以及如何加载网络、本地、资源和内存中的图片。接着讲解了Icon的优势和使用,以及ImageIcon作为自定义图形图标的作用和构造方法。最后总结了Flutter图片组件的关键知识点。
摘要由CSDN通过智能技术生成

前言

Flutter 作为Google出品的一个新兴的跨平台移动客户端UI开发框架,正在被越来越多的开发者和组织使用,包括阿里的咸鱼、腾讯的微信等。

示意图

今天,我主要讲解Flutter中图片组件方面的Widget,包括Image、Icon、ImageIcon,希望你们会喜欢。

示意图

1. Image

1.1 作用

显示图片,主要支持的加载方式:本地图片、资源图片 & 网络图片。

1.2 常用属性

const Image({

Key key,

@required this.image,// ImageProvider,必填参数,接收一个ImageProvider 类型的值

this.semanticLabel, // String,图片的描述

this.excludeFromSemantics = false, // bool,是否从语义上排除该图片,默认值为false

this.width, // double,图片的宽度

this.height, // double,图片的高度

this.color, // Color,图片的前景色,一般不设置或设置透明色,会覆盖掉图片,一般会和colorBlendMode结合使用

this.colorBlendMode, // BlendMode,一般和color结合使用,设置color的混合模式

this.fit, // BoxFit,设置图片的显示模式

this.alignment = Alignment.center, // AlignmentGeometry,用于设置图片的对齐方式,默认值:Alignment.center

this.repeat = ImageRepeat.noRepeat, // ImageRepeat,图片的重复方式,当图片没有完全覆盖掉容器时使用。默认值:ImageRepeat.noRepeat

...

})

下面,将详细讲解Image的属性。

1.3 属性image

接收一个ImageProvider类型的值。ImageProvider是一个抽象类

实现类主要包括:AssetImage、MemoryImage、NetworkImage、FileImage,分别表示可从资源、内存、网络 & 文件中获取图片

// 加载网络图片

Image.network(String src, {

Key key,

double scale = 1.0,

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,

Map headers,

})

// 加载本地文件

Image.file(File file, {

Key key,

double scale = 1.0,

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,

})

// 从项目资源中加载

Image.asset(String name, {

Key key,

AssetBundle bundle,

this.semanticLabel,

this.excludeFromSemantics = false,

double scale,

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,

String package,

this.filterQuality = FilterQuality.low,

})

// 从内存中加载

Image.memory(Uint8List bytes, {

Key key,

double scale = 1.0,

this.semanticLabel,

this.excludeFromSemantics = false,

this.width,

this.height,

this.color,

this.colorBlendMode,

this.fit,

this.alignment = Alignm

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值