Flutter - 加载网络图片的几种方式

本文介绍了在Flutter中加载网络图片的多种方法,包括直接使用`Image.network`,使用`FadeInImage`实现淡入效果,以及使用`CachedNetworkImage`进行缓存。示例代码展示了如何设置默认占位图、加载 Animated Gif 和应用内图片作为占位图。通过这些方法,可以提升用户体验并优化图片加载过程。
摘要由CSDN通过智能技术生成

@override

Widget build(BuildContext context) {

return new MaterialApp(

title: ‘Image Demo’,

home: new HomePage(),

);

}

}

class HomePage extends StatefulWidget {

@override

State createState() => new _HomePageState();

}

class _HomePageState extends State {

@override

Widget build(BuildContext context) {

return new Scaffold(

appBar: new AppBar(title: new Text(‘Web Image Demo Page’),),

body: new ListView(children: [

Container(

margin: EdgeInsets.only(bottom: 12.0),

decoration: BoxDecoration(color: Colors.grey),

child: Column(children: [

Image.network(

‘https://raw.githubusercontent.com/flutter/website/master/_includes/code/layout/lakes/images/lake.jpg’,

),

Text(‘Image.network’)

],),

),

Container(

margin: EdgeInsets.only(bottom: 12.0),

decoration: BoxDecoration(color: Colors.grey),

child: Column(children: [

Image.network(

‘https://github.com/flutter/plugins/raw/master/packages/video_player/doc/demo_ipod.gif?raw=true’,

),

Text(‘Image.network Animated Gifs’)

],),

),

],),

);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值