flutter image demo 主要展示图片与动画处理的案例。比如:网络图片加载、图片预览、图片缩放、json动画处理等等。

Overview

flutter_image_demo

flutter image demo 主要展示图片与动画处理的案例。
比如:网络图片加载、图片预览、图片缩放、json动画处理等等。

本项目使用到以下插件: cached_network_imagephoto_viewlottieflutter_svgsvgaplayer_flutter

Catalog (目录)

  • Mind Map (思维导图)
  • Getting started (开始前准备)
  • Example of Network Image (加载网络图片案例)
  • Example of PhotoView (图片预览案例)
  • Example of Svga (加载Svga动画案例)
  • Example of Lottie (加载json动画案例)

Mind Map


Getting started

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
  ...
  cached_network_image: ^3.0.0
  photo_view: ^0.12.0
  flutter_svg: ^0.22.0
  lottie: ^1.2.1
  svgaplayer_flutter: ^2.0.0

If you want to use wrapped dependency packages, In your library add the following file:

Example of Network Image

import 'package:flutter_image_demo/manager/sn_image_manager.dart';

  //Widget
  Center(
    child: SNCacheNetworkImage(
      progressIndicatorBuilder: (context, url, progress) => Center(
        child: CircularProgressIndicator(
          value: progress.progress,
        ),
      ),
      imageUrl: 'https://blurha.sh/assets/images/img1.jpg',
    ),
  )
  
  
  //ImageProvider
  Image(
    image: CachedNetworkImageProvider(
      'https://loremflickr.com/320/240/music?lock=0',
    ),
  )
  

You can find more examples in the example_image_cache_page.dart

Example of PhotoView

import 'package:flutter_image_demo/manager/sn_image_manager.dart';

//Preview
//PreviewOpenType { dialog, push, bottomSheet }
Center(
  child: SNPreviewImageWrapper(
    imageUrl: 'https://loremflickr.com/320/240/music?lock=1',
    previewEnable: true,
    previewOpenType: PreviewOpenType.dialog,
  ),
)

//Gallery
GridView.builder(
  itemCount: images.length,
  gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
      crossAxisCount: 3),
  itemBuilder: (BuildContext context, int index) =>
      SNPreviewImageGallery(
    imageUrl: images[index],
    galleryItems: images,
    initialIndex: index,
    verticalGallery: verticalGallery,
  ),
)

Example of Svga

import 'package:flutter_image_demo/manager/sn_image_manager.dart';

//common
Center(
  child: SNSvgaplayerWrapper(
    imageUrl: samples[index].last,
  ),
),

//AnimationController
class ControlDetail extends StatefulWidget {
  final String imageUrl;

  const ControlDetail(this.imageUrl, {Key? key}) : super(key: key);

  @override
  _ControlDetailState createState() => _ControlDetailState();
}

class _ControlDetailState extends State<ControlDetail>
    with TickerProviderStateMixin {
  late final _controller = SVGAAnimationController(vsync: this);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.imageUrl),
      ),
      body: SingleChildScrollView(
        child: Stack(
          children: [
            Center(
              child: SNSvgaplayerWrapper(
                imageUrl: widget.imageUrl,
                controller: _controller,
              ),
            ),
            AnimatedBuilder(
              animation: _controller,
              builder: (context, _) => Row(
                children: <Widget>[
                  Expanded(
                    child: Slider(
                      value: _controller.value,
                      onChanged: (newValue) {
                        _controller.value = newValue;
                      },
                    ),
                  ),
                  IconButton(
                    icon: Icon(_controller.isAnimating
                        ? Icons.stop
                        : Icons.play_arrow),
                    onPressed: () {
                      setState(() {
                        if (_controller.isAnimating) {
                          _controller.stop();
                        } else {
                          _controller.repeat();
                        }
                      });
                    },
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Example of Lottie

import 'package:lottie/lottie.dart';

//Assert
Lottie.asset('assets/LottieLogo1.json')

//Network
Lottie.network(
      'https://assets10.lottiefiles.com/datafiles/QeC7XD39x4C1CIj/data.json'),
)

//Zip file
Lottie.asset('assets/lottiefiles/angel.zip')

//No repeat
Lottie.asset(
  'assets/LottieLogo1.json',
  repeat: false,
),

//Error builder
Lottie.network(
  'https://example.does.not.exist/lottie.json',
  errorBuilder: (context, exception, stackTrace) {
    return Center(
      child: Icon(
        Icons.broken_image,
        color: Colors.grey[400],
        size: 40.0,
      ),
    );
  },
)

You can find more examples in the example_lottie_page.dart

You might also like...

A flutter package to convert any widget to an Image.

A flutter package to convert any widget to an Image.

Davinci A package to convert any widget to an image which can be saved locally or can be shared to other apps and chats. 📹 Preview ℹ️ Usage Prerequis

Dec 20, 2022

Flutter Image Upload From Gallery

Image Upload From Gallery Image upload from gallery to Backend Dependencies image_picker: ^0.8.4+1 http: ^0.13.3 dio: ^4.0.0 Getting Started Image upl

Oct 6, 2021

Multi image pixker using the image_picker package in flutter

multi_image_selection A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you st

Oct 13, 2021

Flutter Package to Pick Image From Gallery or Camera

Flutter Package to Pick Image From Gallery or Camera

image_picker_gallery_camera Flutter Package to Pick Image From Gallery or Camera Getting Started A Flutter plugin for iOS and Android for picking imag

Oct 5, 2022

A flutter package for image carousels.

A flutter package for image carousels.

flutter_image_carousel A flutter package for image carousels. Supports both Asset and Network images. Example new ImageCarousel( ImageProvider[

Aug 9, 2021

Flutter gallery - Image, Audio, Video & File.

Flutter gallery  - Image, Audio, Video & File.

Flutter Gallery Getting Started For help getting started with Flutter, view our online documentation.

Sep 26, 2022

A Flutter image editor with support for paint, text, filters, emojis, stickers and more

A Flutter image editor with support for paint, text, filters, emojis, stickers and more

Flutter Image Editor Plugin with simple, easy support for image editing using Paints, Text, Filters, Emoji and Sticker like stories.

Dec 22, 2022

Flutter BlurHash - Compact representation of a placeholder for an image.

Flutter BlurHash - Compact representation of a placeholder for an image.

Compact representation of a placeholder for an image. Encode a blurry image under 30 caracters for instant display like used by Medium. Maintainer: @Solido

Dec 30, 2022

Flutter package for image editing

Flutter package for image editing

You can edit image using this package and also you can create flex preview image by setting foreground to null. For now, you can use only asset files.

Nov 21, 2022
Owner
null
Loading indicator GIFs. Material and Cupertino (Android and iOS) loading indicators in assorted sizes. Use as placeholders for loading remote image assets. Demo: https://gallery.codelessly.com/flutterwebsites/loadinggifs/

Loading GIFs High quality Android and iOS loading spinners. View Demo Loading GIFs is a collection of high fidelity loading animations in GIF format.

Codelessly 31 Dec 23, 2022
Flutter package for Image Carousel It is an image carousel widget.

Snapshot Carousel Flutter package for Image Carousel It is an image carousel widget. Supported platforms Flutter Android Flutter iOS Flutter web Flutt

Mrigank Anand 12 Jun 3, 2021
A powerful official extension library of image, which support placeholder(loading)/ failed state, cache network, zoom pan image, photo view, slide out page, editor(crop,rotate,flip), paint custom etc.

extended_image Language: English| 中文简体 A powerful official extension library of image, which support placeholder(loading)/ failed state, cache network

FlutterCandies 1.6k Dec 31, 2022
A simple Flutter Package to Mimic iMessage Image Picker for Flutter

A simple Flutter Package to Mimic iMessage Image Picker for Flutter

Paras Jain 64 Dec 26, 2022
A Flutter widget that paints an image and moves it at a slower speed than the main scrolling content.

A Flutter widget that paints an image and moves it at a slower speed than the main scrolling content. Installation Add dependency to your pubspec.yaml

Anatoly Pulyaevskiy 272 Dec 23, 2022
📸 Easy to use yet very customizable zoomable image widget for Flutter, Photo View provides a gesture sensitive zoomable widget. Photo View is largely used to show interacive images and other stuff such as SVG.

Flutter Photo View A simple zoomable image/content widget for Flutter. PhotoView enables images to become able to zoom and pan with user gestures such

Fire Slime Games 1.7k Jan 3, 2023
Flutter plugin that allows you to display multi image picker on iOS and Android. 👌🔝🎉

IMPORTANT: This repository has been archived and no longer mantained. As I don't have time anymore to work on the package it became very outdated. For

Radoslav Vitanov 898 Apr 29, 2021
Image caching system for flutter

image_cacheing image_cacheing is an image caching package. It is currently tested for Android applications. ImageCacheing widget takes url as a param.

evolving_kid 3 May 31, 2021
A flutter tool to generate beautiful code snippets in the form of an image.

A flutter tool to generate beautiful code snippets in the form of an image.

Mahesh Jamdade 4 Jan 18, 2022
Simple and effective cross platform image saver for flutter, supported web and desktop

Simple and effective cross platform image saver for flutter, supported web and desktop

7c00 3 Oct 5, 2022