当前位置:网站首页>[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 )

边栏推荐
猜你喜欢
![[AUTOSAR eight OS]](/img/ac/fbc84c077ff9c94c840e1871171d19.png)
[AUTOSAR eight OS]

AEM: Nanlin fan Ben et al. - plant rhizosphere growth promoting bacteria control soybean blight

【案例分享】让新时代教育发展与“数”俱进
![[AUTOSAR VI description document]](/img/3d/1382acbc4054ab218485a12b7b4e6b.png)
[AUTOSAR VI description document]

Leetcode-849: maximum distance to the nearest person

Vulkan practice first bullet
![[AUTOSAR nine c/s principle Architecture]](/img/59/ce32c0ff58ef5d8385fe950136175b.png)
[AUTOSAR nine c/s principle Architecture]

指针初阶(基础)

利亚德:Micro LED 产品消费端首先针对 100 英寸以上电视,现阶段进入更小尺寸还有难度

File operation io-part2
随机推荐
测试右移:线上质量监控 ELK 实战
基于ARM RK3568的红外热成像体温检测系统
AttributeError: ‘tuple‘ object has no attribute ‘layer‘问题解决
研发一款国产ARM智能边缘计算网关需要什么
[shutter] image component (the placeholder | transparent_image transparent image plug-in is loaded into the memory)
解决ReactNative使用webView存在缓存问题
1.12 - 指令
Baidu AI Cloud takes the lead in building a comprehensive and standardized platform for smart cloud
Leetcode-871: minimum refueling times
【爱死机】《吉巴罗》被忽略的细节
数据分析思维分析犯法和业务知识——分析方法(一)
图解网络:什么是虚拟路由器冗余协议 VRRP?
Leetcode-1964: find the longest effective obstacle race route to each position
Vulkan practice first bullet
Infrared thermography temperature detection system based on arm rk3568
Rust字符串切片、结构体和枚举类
File operation io-part2
Machine learning: numpy version linear regression predicts Boston house prices
Meaning of Tencent cloud free SSL certificate extension file
Rust ownership (very important)