当前位置:网站首页>[shutter] image component (cached_network_image network image caching plug-in)
[shutter] image component (cached_network_image network image caching plug-in)
2022-07-03 00:53:00 【Programmer community】
List of articles
- One 、cached_network_image Network picture caching plug-in
- Two 、cached_network_image Load network pictures
- 3、 ... and 、 Complete code example
- Four 、 Related resources
One 、cached_network_image Network picture caching plug-in
Pictures loaded from the network , It can be cached , If you get the picture again, you can get the picture directly from the cache , similar Glide Three level cache mechanism in ;
Cached pictures can be used cached_network_image Plug-in implementation ;
install cached_network_image plug-in unit :
- Search plug-ins : stay https://pub.dev/packages Mid search cached_network_image plug-in unit ;
- Plug-in address : https://pub.dev/packages/cached_network_image
- Configuration plug-ins : stay pubspec.yaml Configure plug-ins in ;
dependencies: cached_network_image: ^2.5.1
- Get plug-ins : Click on pubspec.yaml In the upper right corner of the middle Pub get Button , Get plug-ins ;
- Import header file :
import 'package:cached_network_image/cached_network_image.dart';
Two 、cached_network_image Load network pictures
cached_network_image Network picture caching plug-in , Provides a component for loading network pictures CachedNetworkImage , In this component, you can set the... Displayed in the process of loading pictures placeholder ;
Center( // Before the picture is loaded, it shows placeholder , Display network pictures after loading child: CachedNetworkImage( // Content displayed during loading network pictures , The progress bar is displayed here placeholder: (context, url)=>CircularProgressIndicator(), // Network picture address imageUrl: "/img/cd/8dfd8275b7e578e58bf6d549cd96ba.jpg", ),),
Running effect : The second picture shows the effect of this example ;
Network pictures used :
3、 ... and 、 Complete code example
Complete code example :
import 'package:flutter/material.dart';import 'dart:io';import 'package:path_provider/path_provider.dart';import 'package:transparent_image/transparent_image.dart';import 'package:cached_network_image/cached_network_image.dart';void main() => runApp(MyApp());class MyApp extends StatelessWidget {
// This widget is the root of your application. @override Widget build(BuildContext context) {
return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: MyHomePage(title: 'Flutter Demo Home Page'), ); }}class MyHomePage extends StatefulWidget {
MyHomePage({
Key key, this.title}) : super(key: key); final String title; @override _MyHomePageState createState() => _MyHomePageState();}class _MyHomePageState extends State<MyHomePage> {
int _counter = 0; void _incrementCounter() {
setState(() {
_counter++; }); } /// SD Card path String sdPath; @override void initState() {
// obtain SD Card path getSdPath(); } void getSdPath() async {
String path = (await getExternalStorageDirectory()).path; setState(() {
sdPath = path; }); } @override Widget build(BuildContext context) {
print("sdPath : $sdPath"); return Scaffold( appBar: AppBar( title: Text(widget.title), ), body: Center( child: ListView( children: [ Stack( children: [ // Progress bar Center(child: CircularProgressIndicator(),), Center( // The gradient appears when the network is loaded child: FadeInImage.memoryNetwork( // Placeholder placeholder: kTransparentImage, image: "https://img-blog.csdnimg.cn/2021032321394771.png", ), ) ], ), Center( // Before the picture is loaded, it shows placeholder , Display network pictures after loading child: CachedNetworkImage( // Content displayed during loading network pictures , The progress bar is displayed here placeholder: (context, url)=>CircularProgressIndicator(), // Network picture address imageUrl: "/img/cd/8dfd8275b7e578e58bf6d549cd96ba.jpg", ), ), Stack( children: [ // Progress bar Center(child: CircularProgressIndicator(),), Center( // The gradient appears when the network is loaded child: FadeInImage.assetNetwork( // Placeholder placeholder: "images/waiting.gif", image: "https://img-blog.csdnimg.cn/2021032321394771.png", ), ) ], ), // Picture components , Load a picture from the network /*Image.network( // Picture address "https://img-blog.csdnimg.cn/2021032313493741.png", ),*/ /*Image( image: AssetImage("images/sidalin.png"), ),*/ //Image.asset('images/sidalin2.png', ), /// from SD Card loading picture /*if(sdPath != null) Image.file( File('$sdPath/sidalin3.png'), width: 200, ),*/ ], ) ), floatingActionButton: FloatingActionButton( onPressed: _incrementCounter, tooltip: 'Increment', child: Icon(Icons.add), ), // This trailing comma makes auto-formatting nicer for build methods. ); }}
Running effect :
Four 、 Related resources
Reference material :
- Flutter Official website : https://flutter.dev/
- Flutter Plug in download address : https://pub.dev/packages
- Flutter Developing documents : https://flutter.cn/docs ( Strongly recommend )
- official GitHub Address : https://github.com/flutter
- Flutter The Chinese community : https://flutter.cn/
- Flutter Practical tutorial : https://flutter.cn/docs/cookbook
- Flutter CodeLab : https://codelabs.flutter-io.cn/
- Dart Chinese document : https://dart.cn/
- Dart Developer website : https://api.dart.dev/
- Flutter Chinese net ( unofficial , The translation is very good ) : https://flutterchina.club/ , http://flutter.axuer.com/docs/
- Flutter Related issues : https://flutterchina.club/faq/ ( It is recommended to watch it at the introductory stage )
- GitHub Upper Flutter Open source examples : https://download.csdn.net/download/han1202012/15989510
Blog source download :
GitHub Address : https://github.com/han1202012/flutter_image_widget ( Keep updating with the progress of the blog , There may not be the source code of this blog )
Blog source snapshot : https://download.csdn.net/download/han1202012/16059814 ( The source code snapshot of this blog , You can find the source code of this blog )
边栏推荐
- Shell 实现文件基本操作(切割、排序、去重)
- [shutter] image component (load network pictures | load static pictures | load local pictures | path | provider plug-in)
- How SQLSEVER removes data with duplicate IDS
- Array and collection performance comparison
- Thank you for being together for these extraordinary two years!
- Leetcode-2280: represents the minimum number of line segments of a line graph
- Linux Software: how to install redis service
- 腾讯云免费SSL证书扩展文件含义
- 文件操作IO-Part2
- [AUTOSAR 11 communication related mechanism]
猜你喜欢
文件操作IO-Part2
1.12 - 指令
Liad: the consumer end of micro LED products is first targeted at TVs above 100 inches. At this stage, it is still difficult to enter a smaller size
【AutoSAR 三 RTE概述】
The arm core board / development board of Feiling equipped with Ti am62x made its debut in embedded world 2022
Leetcode-849: maximum distance to the nearest person
Shell 实现文件基本操作(切割、排序、去重)
How to convert Quanzhi a40i/t3 to can through SPI
2022 list of manufacturers of Chinese 3D vision enterprises (guided positioning and sorting scenes)
Hundreds of continuous innovation to create free low code office tools
随机推荐
Machine learning: numpy version linear regression predicts Boston house prices
递归处理组织的几种情况
Tensorflow 2.x(keras)源码详解之第十五章:迁移学习与微调
【AutoSAR 五 方法论】
Reading and writing speed of Reza rz/g2l arm development board storage and network measurement
Some introduction and precautions about XML
这不平凡的两年,感谢我们一直在一起!
瑞萨RZ/G2L ARM开发板存储读写速度与网络实测
[shutter] image component (load network pictures | load static pictures | load local pictures | path | provider plug-in)
Rust ownership (very important)
[AUTOSAR I overview]
Illustrated network: what is virtual router redundancy protocol VRRP?
[AUTOSAR II appl overview]
Rust所有权(非常重要)
Shell implements basic file operations (cutting, sorting, and de duplication)
[AUTOSAR eight OS]
Test shift right: Elk practice of online quality monitoring
Leetcode 294. Flip game II (game theory)
利亚德:Micro LED 产品消费端首先针对 100 英寸以上电视,现阶段进入更小尺寸还有难度
Leetcode-2280: represents the minimum number of line segments of a line graph