当前位置:网站首页>[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.gif
complete 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.gif
Two 、 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.gif
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/16073006 ( The source code snapshot of this blog , You can find the source code of this blog )
边栏推荐
- Leetcode-1964: find the longest effective obstacle race route to each position
- [jetcache] jetcache configuration description and annotation attribute description
- 数组与集合性能比较
- Helm basic learning
- Rk3568 development board evaluation (II): development environment construction
- leetcode-241:为运算表达式设计优先级
- Array and collection performance comparison
- 基于ARM RK3568的红外热成像体温检测系统
- 深度剖析数据在内存中的存储
- 腾讯云免费SSL证书扩展文件含义
猜你喜欢
Vulkan performance and refinement
Advanced pointer (I)
[AUTOSAR VI description document]
[introduction to AUTOSAR seven tool chain]
数据分析思维分析犯法和业务知识——分析方法(一)
利亚德:Micro LED 产品消费端首先针对 100 英寸以上电视,现阶段进入更小尺寸还有难度
FPGA - 7系列 FPGA内部结构之Clocking -04- 多区域时钟
2022上半年值得被看见的10条文案,每一句都能带给你力量!
[AUTOSAR XIII NVM]
Thank you for being together for these extraordinary two years!
随机推荐
antv x6节点拖拽到画布上后的回调事件(踩大坑记录)
Meaning of Tencent cloud free SSL certificate extension file
递归处理组织的几种情况
Lu Zhe, chief scientist of Shiping information: building data and personnel centered security capabilities
Logback configuration file
[introduction to AUTOSAR seven tool chain]
全志A40i/T3如何通过SPI转CAN
数组与集合性能比较
leetcode-934:最短的桥
Linux Software: how to install redis service
Leetcode-934: the shortest Bridge
[shutter] image component (load network pictures | load static pictures | load local pictures | path | provider plug-in)
The "2022 China Digital Office Market Research Report" can be downloaded to explain the 176.8 billion yuan market in detail
百度智能云牵头打造智能云综合标准化平台
测试右移:线上质量监控 ELK 实战
【AutoSAR 六 描述文件】
Rust所有权(非常重要)
Thread start and priority
Key detection and sinusoidal signal output developed by Arduino
Thank you for being together for these extraordinary two years!