当前位置:网站首页>[shutter] image component (the placeholder | transparent_image transparent image plug-in is loaded into the memory)
[shutter] image component (the placeholder | transparent_image transparent image plug-in is loaded into the memory)
2022-07-03 00:34:00 【Programmer community】
List of articles
- One 、transparent_image Transparent image plugin
- Two 、 Memory load Placeholder
- 3、 ... and 、 Complete code example
- Four 、 Related resources
One 、transparent_image Transparent image plugin
install transparent_image plug-in unit :
- Search plug-ins : stay https://pub.dev/packages Mid search transparent_image plug-in unit ;
- Plug-in address : https://pub.dev/packages/transparent_image
- Configuration plug-ins : stay pubspec.yaml Configure plug-ins in ;
dependencies: transparent_image: ^2.0.0- 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:transparent_image/transparent_image.dart';Two 、 Memory load 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 ;
Code example :
Stack( children: [ // Progress bar Center(child: CircularProgressIndicator(),), Center( // The gradient appears when the network is loaded child: FadeInImage.memoryNetwork( // Placeholder placeholder: kTransparentImage, image: "/img/77/2697601bd73b0330cda8b8835a2857.jpg", ), ) ],),Running effect : The progress bar is always , At the beginning of the FadeInImage Components are transparent , Show progress bar , Then it becomes opaque , Progress bar is overwritten , But keep turning in the back ;

Displayed network pictures : ( Learn the lesson of the last blog , Use landscape pictures )

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: "/img/77/2697601bd73b0330cda8b8835a2857.jpg", ), ) ], ), // 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 )

边栏推荐
- Where can I check the foreign literature of economics?
- Monitor container runtime tool Falco
- Angled detection frame | calibrated depth feature for target detection (with implementation source code)
- Mutual exclusion and synchronization of threads
- logback配置文件
- Confluence的PDF导出中文文档异常显示问题解决
- antv x6节点拖拽到画布上后的回调事件(踩大坑记录)
- NC24840 [USACO 2009 Mar S]Look Up
- FAQ | FAQ for building applications for large screen devices
- 论文的设计方案咋写?
猜你喜欢

Multiprocess programming (I): basic concepts

What are the recommended thesis translation software?

Which websites can I search for references when writing a thesis?

Detailed explanation of pod life cycle

Gan model architecture in mm

Sysdig analysis container system call

有哪些比较推荐的论文翻译软件?

Logback configuration file

多进程编程(一):基本概念

Talk with the interviewer about the pit of MySQL sorting (including: duplicate data problem in order by limit page)
随机推荐
Nc50528 sliding window
v8
Where can I find the English literature of the thesis (except HowNet)?
Array common operation methods sorting (including ES6) and detailed use
Rust所有权(非常重要)
Introduction of UART, RS232, RS485, I2C and SPI
What is the standard format of a 2000-3000 word essay for college students' classroom homework?
NC24840 [USACO 2009 Mar S]Look Up
使用jenkins之二Job
node_modules删不掉
Maya fishing house modeling
FAQ | FAQ for building applications for large screen devices
Is there a specific format for English papers?
微信小程序获取某个元素的信息(高、宽等),并将px转换为rpx。
数组常用操作方法整理(包含es6)及详细使用
【雅思阅读】王希伟阅读P2(阅读填空)
Slf4j + logback logging framework
There is an unknown problem in inserting data into the database
Feature Engineering: summary of common feature transformation methods
pod生命周期详解