Flutter 渐变
1. 加载项目中的图片:
在项目根目录中创建 images 文件夹,然后放入三张图片;
在 yaml 文件中添加;
flutter:
assets:
- images/pic1.jpg
- images/pic2.jpg
- images/pic3.jpg
使用:
newImage.asset('images/pic1.jpg')
加载网络图片:
newImage( image:newNetworkImage('http://h.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=0d023672312ac65c67506e77cec29e27/9f2f070828381f30dea167bbad014c086e06f06c.jpg'), )
用占位符淡入图片
transparent_image: ^0.1.0
import'package:transparent_image/transparent_image.dart';
new FadeInImage.memoryNetwork( placeholder: kTransparentImage, fadeInDuration: const Duration(seconds: 50), // 持续时间,默认 700 ms image: 'https://github.com/flutter/website/blob/master/_includes/code/layout/lakes/images/lake.jpg?raw=true', )
使用缓存图片
cached_network_image: ^0.4.1
import'package:cached_network_image/cached_network_image.dart';
new CachedNetworkImage( placeholder: new CircularProgressIndicator(), imageUrl: 'https://github.com/flutter/website/blob/master/_includes/code/layout/lakes/images/lake.jpg?raw=true', errorWidget: new Image.asset('images/pic1.jpg'), ),