当前位置:网站首页>[shutter] image component (configure local GIF image resources | load placeholder with local resources)
[shutter] image component (configure local GIF image resources | load placeholder with local resources)
2022-07-03 00:53:00 【Programmer community】
List of articles
- One 、 Configure local gif Image resources
- Two 、 Local resource loading Placeholder
- 3、 ... and 、 Complete code example
- Four 、 Related resources
One 、 Configure local gif Image resources
To configure assets Image resources :
take gif Copy the picture to Flutter In the root directory images Under the table of contents ;

stay pubspec.yaml Configuration in the directory images/waiting.gif Image resources ;
flutter: assets: - images/waiting.gifcomplete pubspec.yaml The configuration file :
name: flutter_image_widgetdescription: A new Flutter application.version: 1.0.0+1environment: sdk: ">=2.1.0 <3.0.0"dependencies: flutter: sdk: flutter cupertino_icons: ^0.1.2 path_provider: ^2.0.1 transparent_image: ^2.0.0 cached_network_image: ^2.5.1dev_dependencies: flutter_test: sdk: flutterflutter: uses-material-design: true assets: - images/sidalin.png - images/sidalin2.png - images/waiting.gifTwo 、 Local resource loading Placeholder
Placeholder Is a placeholder control , When the picture is not ready , Such as getting pictures from the Internet , First use Placeholder Occupy the position of the picture component ;
FadeInImage.assetNetwork Create a gradient image component , Get pictures from the Internet , Placeholder Get from picture resources ;
Code example :
Stack( children: [ Center( // Display the local resource image when the network is loaded child: FadeInImage.assetNetwork( // Placeholder placeholder: "images/waiting.gif", image: "/img/b0/1fddd83439f6e340b2b1a9229876e7.jpg", ), ) ],),Running effect : When the first picture is loaded GIF Images ;

Displayed network pictures :
wait for gif picture :

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: [ Center( // Display the local resource image when the network is loaded child: FadeInImage.assetNetwork( // Placeholder placeholder: "images/waiting.gif", image: "/img/b0/1fddd83439f6e340b2b1a9229876e7.jpg", ), ) ], ), 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: "https://img-blog.csdnimg.cn/20210324100419204.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. ); }}pubspec.yaml The configuration file :
name: flutter_image_widgetdescription: A new Flutter application.version: 1.0.0+1environment: sdk: ">=2.1.0 <3.0.0"dependencies: flutter: sdk: flutter cupertino_icons: ^0.1.2 path_provider: ^2.0.1 transparent_image: ^2.0.0 cached_network_image: ^2.5.1dev_dependencies: flutter_test: sdk: flutterflutter: uses-material-design: true assets: - images/sidalin.png - images/sidalin2.png - images/waiting.gifRunning 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/16073006 ( The source code snapshot of this blog , You can find the source code of this blog )

边栏推荐
- Vulkan并非“灵药“
- FPGA - 7系列 FPGA内部结构之Clocking -04- 多区域时钟
- 【小程序项目开发-- 京东商城】uni-app之自定义搜索组件(中)-- 搜索建议
- leetcode-241:为运算表达式设计优先级
- [AUTOSAR VI description document]
- Web2.0 giants have deployed VC, and tiger Dao VC may become a shortcut to Web3
- Nc17059 queue Q
- Leetcode 294. Flip game II (game theory)
- Initial order of pointer (basic)
- 百度智能云牵头打造智能云综合标准化平台
猜你喜欢

详解RDD基本概念、RDD五大属性

Initial order of pointer (basic)

University of Toronto: Anthony coach | the conditions of deep reinforcement learning can induce dynamic risk measurement

【AutoSAR 十一 通信相关机制】

指针进阶(一)

Shell implements basic file operations (SED edit, awk match)
![[AUTOSAR nine c/s principle Architecture]](/img/59/ce32c0ff58ef5d8385fe950136175b.png)
[AUTOSAR nine c/s principle Architecture]

Shell 实现文件基本操作(切割、排序、去重)

Win10 can't be installed in many ways Problems with NET3.5

深度剖析数据在内存中的存储
随机推荐
AttributeError: ‘tuple‘ object has no attribute ‘layer‘问题解决
Callback event after the antv X6 node is dragged onto the canvas (stepping on a big hole record)
Cordova plugin device obtains the device information plug-in, which causes Huawei to fail the audit
基于ARM RK3568的红外热成像体温检测系统
mysql 多表联合删除
Detailed explanation of pod life cycle
飞凌搭载TI AM62x的ARM核心板/开发板首发上市,亮相Embedded World 2022
线程的启动与优先级
Leetcode-2280: represents the minimum number of line segments of a line graph
Leetcode-1964: find the longest effective obstacle race route to each position
How to convert Quanzhi a40i/t3 to can through SPI
【AutoSAR 九 C/S原理架构】
Deep analysis of data storage in memory
Use Jenkins II job
kubernetes资源对象介绍及常用命令(五)-(NFS&PV&PVC)
Rust ownership (very important)
【爱死机】《吉巴罗》被忽略的细节
关于XML一些介绍和注意事项
Meaning of Tencent cloud free SSL certificate extension file
Win10 can't be installed in many ways Problems with NET3.5