ImageDecoder class

A class responsible for decoding images from file sources.

The ImageDecoder provides functionality to read and decode image files into a format suitable for rendering in Flutter applications. This class handles both the decoding process and the construction of widgets to display the decoded images.

Methods:

  • Future<ui.Image> decodeImage(File file):

    • Decodes an image from the specified file into a ui.Image object.
    • Parameters:
      • file: A File object representing the image file to decode.
    • Returns: A Future<ui.Image> that resolves to the decoded image.
    • Example:
      ui.Image decodedImage = await imageDecoder.decodeImage(myImageFile);
      
  • Widget loadImageFromFile(File file, BoxFit fit, double width, double height):

    • Loads an image from the specified file and returns a widget displaying the image.
    • Uses a FutureBuilder to handle the asynchronous image decoding process and display a loading indicator while the image is being decoded.
    • Parameters:
      • file: A File object representing the image file to load.
      • fit: A BoxFit value that defines how the image should be fitted into the given width and height.
      • width: A double specifying the desired width of the image.
      • height: A double specifying the desired height of the image.
    • Returns: A Widget that displays the image or a loading indicator/error placeholder if applicable.
    • Example:
      Widget imageWidget = imageDecoder.loadImageFromFile(myImageFile, BoxFit.cover, 100.0, 100.0);
      

Usage Example:

Here is an example of how to use the ImageDecoder class to decode and display an image in a Flutter application:

void main() {
  final imageDecoder = ImageDecoder();
  final imageFile = File('path/to/image.png');
  runApp(MaterialApp(
    home: Scaffold(
      body: imageDecoder.loadImageFromFile(imageFile, BoxFit.cover, 300.0, 300.0),
    ),
  ));
}

Note:

Ensure that the app has the necessary permissions to read files from the file system, especially when running on different platforms (Android, iOS, etc.).

Constructors

ImageDecoder.new()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

decodeImage(File file) Future<Image>
Decodes an image from the specified file into a ui.Image object.
loadImageFromFile(File file, BoxFit fit, double width, double height) Widget
Loads an image from the specified file and returns a widget displaying the image.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited