• Stars
    star
    154
  • Rank 235,343 (Top 5 %)
  • Language
    Dart
  • License
    MIT License
  • Created about 4 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A multifunctional Flutter image widget

OctoImage

pub package Build Status codecov

An image library for showing placeholders, error widgets and transform your image.

Recommended using with CachedNetworkImage version 2.2.0 or newer.

Getting Started

The OctoImage widget needs an ImageProvider to show the image. You can either supply the widget with a placeholder or progress indicator, an ImageBuilder and/or an error widget.

However, what OctoImage makes is the use of OctoSets. OctoSets are predefined combinations of placeholders, imagebuilders and error widgets.

So, either set the all the components yourself:

OctoImage(
  image: CachedNetworkImageProvider(
      'https://blurha.sh/assets/images/img1.jpg'),
  placeholderBuilder: OctoPlaceholder.blurHash(
    'LEHV6nWB2yk8pyo0adR*.7kCMdnj',
  ),
  errorBuilder: OctoError.icon(color: Colors.red),
  fit: BoxFit.cover,
);

Or use an OctoSet:

OctoImage.fromSet(
  fit: BoxFit.cover,
  image: CachedNetworkImageProvider(
    'https://upload.wikimedia.org/wikipedia/commons/thumb/4/4e/Macaca_nigra_self-portrait_large.jpg/1024px-Macaca_nigra_self-portrait_large.jpg',
  ),
  octoSet: OctoSet.circleAvatar(
    backgroundColor: Colors.red,
    text: Text("M"),
  ),
);

The CircleAvatar set shows a colored circle with the text inside during loading and when the image failed loading. When the image loads it animates to the image clipped as a circle.

ImageProviders

The recommended one is CachedNetworkImageProvider, as that supports the progress indicator, error and caching. It also works on Android, iOS, web and macOS, although without caching on the web. Make sure you use at least version 2.2.0.

The second best is NetworkImage, but any ImageProvider works in theory. However, for some ImageProviders (such as MemoryImage) it doesn't make sense to use OctoImage.

Placeholders and progress indicators

It would be best if you used either a placeholder or a progress indicator, but not both. Placeholders are only building once the image starts loading, but progress indicators are rebuilt every time new progress information is received. So if you don't use that progress indication, for example, with a static image, you should use a placeholder.

The most simple progress indicators use a CircularProgressIndicator.

OctoImage(
  image: image,
  progressIndicatorBuilder: (context) => 
    const CircularProgressIndicator(),
),
OctoImage(
  image: image,
  progressIndicatorBuilder: (context, progress) {
    double value;
    if (progress != null && progress.expectedTotalBytes != null) {
      value =
          progress.cumulativeBytesLoaded / progress.expectedTotalBytes;
    }
    return CircularProgressIndicator(value: value);
  },
),

However, because these are used so often, we prebuild these widgets for you. Just use OctoProgressIndicator.circularProgressIndicator()

OctoImage(
  image: image,
  progressIndicatorBuilder: OctoProgressIndicator.circularProgressIndicator(),
),

All included placeholders and progress indicators:

OctoPlaceholder Explanation
blurHash Shows a BlurHash image
circleAvatar Shows a colored circle with a text
circularProgressIndicator Shows a circularProgressIndicator with indeterminate progress.
frame Shows the Flutter Placeholder
OctoProgressIndicator Explanation
circularProgressIndicator Shows a simple CircularProgressIndicator

Error widgets

Error widgets are shown when the ImageProvider throws an error because the image failed loading. You can build a custom widget, or use the prebuild widgets:

OctoImage(
  image: image,
  errorBuilder: (context, error, stacktrace) =>
    const Icon(Icons.error),
);
OctoImage(
  image: image,
  errorBuilder: OctoError.icon(),
),

All included error widgets are:

OctoError Explanation
blurHash Shows a BlurHash placeholder with an error icon.
circleAvatar Shows a colored circle with a text
icon Shows an icon, default to Icons.error
placeholderWithErrorIcon Shows any placeholder with an icon op top.

Image builders

Image builders can be used to adapt the image before it is shown. For example the circleAvatar clips the image in a circle, but you could also add an overlay or anything else.

The builder function supplies a context and a child. The child is the image widget that is rendered.

An example that shows the image with 50% opacity:

OctoImage(
  image: image,
  imageBuilder: (context, child) => Opacity(
    opacity: 0.5,
    child: child,
  ),
),

A prebuild image transformer that clips the image as a circle:

OctoImage(
  image: image,
  imageBuilder: OctoImageTransformer.circleAvatar(),
),

All included image transformers are:

OctoImageTransformer Explanation
circleAvatar Clips the image in a circle

OctoSets

You get the most out of OctoImage when you use OctoSets. These sets contain a combination of a placeholder or progress indicator, an image builder and/or an error widget builder. It always contains at least a placeholder or progress indicator and an error widget.

You can use them with OctoImage.fromSet:

OctoImage.fromSet(
  image: image,
  octoSet: OctoSet.blurHash('LEHV6nWB2yk8pyo0adR*.7kCMdnj'),
),

All included OctoSets are:

OctoSet Explanation
blurHash Shows a blurhash as placeholder and error widget. When an error is thrown an icon is shown on top.
circleAvatar Shows a colored circle with text during load and error. Clips the image after successful load.
circularIndicatorAndIcon Shows a circularProgressIndicator with or without progress and an icon on error.

Contribute

If you would like to contribute to the plugin (e.g. by improving the documentation, solving a bug or adding a cool new feature), please carefully review our contribution guide and send us your pull request.

PR's with any new prebuild widgets or sets are highly appreciated.

Support

  • Feel free to open an issue. Make sure to use one of the templates!
  • Commercial support is available. Integration with your app or services, samples, feature request, etc. Email: [email protected]
  • Powered by: baseflow.com

More Repositories

1

PhotoView

Implementation of ImageView for Android that supports zooming, by various touch gestures.
Java
18,686
star
2

flutter_cached_network_image

Download, cache and show images in a flutter app
Dart
2,370
star
3

flutter-permission-handler

Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions.
Dart
1,957
star
4

LottieXamarin

Render After Effects animations natively on Android, iOS, MacOS and TvOS for Xamarin
C#
1,211
star
5

flutter-geolocator

Android and iOS Geolocation plugin for Flutter
Dart
1,202
star
6

XamarinMediaManager

Cross platform Xamarin plugin to play and control Audio and Video
C#
760
star
7

flutter_cache_manager

Generic cache manager for flutter
Dart
734
star
8

XF-Material-Library

A Xamarin Forms library for implementing Material Design
C#
652
star
9

ExoPlayerXamarin

Xamarin bindings library for the Google ExoPlayer library
C#
150
star
10

Chameleon

Chameleon is a flexible media player build with Xamarin.Forms
C#
149
star
11

flutter-geocoding

A Geocoding plugin for Flutter
Dart
129
star
12

Xamarin-Sidebar

A slideout navigation control for Xamarin.iOS
C#
114
star
13

FoldingCell

FoldingCell is an expanding content cell inspired by folding paper material
C#
55
star
14

screenrecorder

Flutter package which can be used to record flutter widgets
Dart
54
star
15

flutter-permission-plugins

This repo contains a collection of permission related Flutter plugins which can be used to request permissions to access device resources in a cross-platform way.
Dart
52
star
16

MvxForms

Sample App with Xamarin.Forms and MvvmCross
C#
46
star
17

flutter-contacts-plugin

Contact plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to read, create and update contacts from the address book.
Dart
40
star
18

HugoStructuredData

Collection of structured data snippets in Google preferred JSON-LD format, with support for Hugo
HTML
40
star
19

NavigationTabBarXamarin

Navigation tab bar with colorful interactions for Xamarin Android
C#
39
star
20

InfiniteCycleViewPagerXamarin

Infinite cycle ViewPager with two-way orientation and interactive effect.
C#
36
star
21

XamarinItemTouchHelper

Basic example of using ItemTouchHelper to add drag & drop and swipe-to-dismiss to RecyclerView for Xamarin
C#
36
star
22

VlcXamarin

Xamarin.Android bindings for VLC player
C#
34
star
23

flutter-google-api-availability

Check the availability of Google Play services on the current device
Dart
34
star
24

NavigationTabStripXamarin

Navigation tab strip with smooth interaction
C#
24
star
25

FantasySlideXamarin

Another sliding menu base on DrawerLayout
C#
20
star
26

DiagonalLayoutXamarin

With Diagonal Layout explore new styles and approaches on material design
C#
19
star
27

LoaderViewXamarin

Library that enables TextView of ImageView to show loading animation while waiting for the text and image get loaded
C#
17
star
28

FloatingNavigationView

A simple Floating Action Button that shows an anchored Navigation View
C#
16
star
29

flutter-essentials

Essential cross platform APIs for your Flutter apps
Dart
16
star
30

flutter_wizard

A library that makes it easy for you to create your own custom wizard.
Dart
15
star
31

flutter-video-bloc

Dart
14
star
32

GuardedActions

A library to increase the error handling, testability and reusability for all your MVVM driven apps!
C#
14
star
33

MaterialDesignHelpers

Default colors and dimens per Material Design guidelines and Android Design guidelines inside one library.
C#
13
star
34

HoverXamarin

A floating menu library for Xamarin Android.
C#
12
star
35

animalstat

Open source flutter app to track your livestock
Dart
11
star
36

byteplot

A Dart command-line tool for Flutter to make your life easier
Dart
11
star
37

FlipShareXamarin

It's a flip way to show share widget.
C#
11
star
38

AndroidSlidingUpPanelXamarin

This library provides a simple way to add a draggable sliding up panel to your Android app
C#
11
star
39

FFmpegMediaMetadataRetrieverXamarin

FFmpegMediaMetadataRetriever provides a unified interface for retrieving frame and meta data from an input media file.
C#
10
star
40

full-stack-on-rust

Source code and documentation for our 'full stack on rust' meetup on 29-9-2022
Rust
8
star
41

InteractiveMediaAdsXamarin

IMA Android SDK v3 for Xamarin
C#
8
star
42

AutoLinkTextViewXamarin

AutoLinkTextView is TextView that supports Hashtags (#), Mentions (@) , URLs (http://), Phone and Email automatically detecting and ability to handle clicks.
C#
8
star
43

GoogleVRXamarin

Xamarin bindings library for the Google VR library
C#
8
star
44

flutter-blues

Flutter plugin to provide easy access to platform specific Bluetooth low energy services
Dart
7
star
45

flutter_swipe_detector

A Flutter package to detect your swipe directions and provides you with callbacks to handle them.
Dart
7
star
46

cheat-sheets

This repo contains a set of cheat sheets often used by the Baseflow crew.
7
star
47

WaveSideBarXamarin

An Index Side Bar With Wave Effect
C#
6
star
48

VerticalViewPagerXamarin

Vertically ViewPager and vertically transformer for Xamarin Android
C#
5
star
49

flutter_uwb

A Flutter plugin for working with Ultra Wide Band sensors.
Dart
5
star
50

baseflow_plugin_template

Template for the Baseflow flutter plugins
Dart
4
star
51

flutter_state_management_demo

A demonstration app showcasing the Baseflow way of State Management in Flutter
Dart
4
star
52

AutoscaleEditTextXamarin

AutoscaleEditText bindings for Xamarin Android
C#
4
star
53

flutter-style-guide

A Flutter style-guide example app
Dart
3
star
54

DSTV.Net

A basic Tekla DSTV NC file parser written in C#
C#
3
star
55

flutter-meetup

Sheets and samples for our flutter meetups
Dart
3
star
56

konami_detector

A package to detect your konami codes and executes the provided callbacks.
Dart
3
star
57

stellar-rust-sdk

Welcome to the Rust Stellar SDK repository! This project aims to empower developers with a robust Rust SDK for the Stellar cryptocurrency network. Leverage Rust's performance and security advantages to build efficient and scalable applications on Stellar. Join us in shaping the future of blockchain development with Stellar and Rust integration.
Rust
3
star
58

terraform-demo

Code and descriptions for the demo on the 14th July 2023
HCL
2
star
59

service_manager

A Flutter plugin to manage the state of platform specific services (e.g. location services).
Dart
2
star
60

EllipsizeTextViewXamarin

The EllipsizeTextView extends TextView, support omit (Ellipsize/Ellipsis) redundant characters in multiple lines situtation.
C#
2
star
61

GuardedActions.Samples

Contains sample project on how to implement the GuardedActions package.
C#
1
star