当前位置:网站首页>[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.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 )
边栏推荐
猜你喜欢
How do educators find foreign language references?
setInterval定时器在ie不生效原因之一:回调的是箭头函数
Introduction of UART, RS232, RS485, I2C and SPI
有哪些比较推荐的论文翻译软件?
redis21道经典面试题,极限拉扯面试官
为什么网站打开速度慢?
【雅思阅读】王希伟阅读P1(阅读判断题)
[shutter] Introduction to the official example of shutter Gallery (learning example | email application | retail application | wealth management application | travel application | news application | a
Sysdig analysis container system call
Hundreds of continuous innovation to create free low code office tools
随机推荐
Multiprocess programming (4): shared memory
Preview word documents online
Mutual exclusion and synchronization of threads
Basic use of shell script
About the practice topic of screen related to unity screen, unity moves around a certain point inside
TypeError: Cannot read properties of undefined (reading ***)
One of the reasons why setinterval timer does not take effect in ie: the callback is the arrow function
[shutter] image component (image component introduction | image constructor | image.network constructor | image.asset constructor)
FAQ | FAQ for building applications for large screen devices
Rust所有权(非常重要)
Markdown使用教程
Wechat applet obtains the information of an element (height, width, etc.) and converts PX to rpx.
Form form instantiation
Feature Engineering: summary of common feature transformation methods
关于XML一些介绍和注意事项
Implement the foreach method of array
Chapter 3 of getting started with MySQL: database creation and operation
Array common operation methods sorting (including ES6) and detailed use
LeedCode1480.一维数组的动态和
[target detection] r-cnn, fast r-cnn, fast r-cnn learning