Skip to main content

flet-image-viewer

flet-image-viewer is a Flet extension for displaying zoomable images and swipeable image galleries in Flet applications.

PyPI Documentation Repository

The package provides FletImageViewer for a single image and FletMultiViewer for a swipeable gallery. Both controls support pinch-to-zoom, configurable image fitting, overlays, and long-press or double-tap events.

Demo

Want to see it in action? Watch the sample demo video.

Installation

Install the published package from PyPI:

pip install flet-image-viewer

Or add it to your application's pyproject.toml:

[project]
dependencies = [
    "flet>=0.86.5",
    "flet-image-viewer",
]

To install the latest version directly from GitHub instead, use:

[project]
dependencies = [
    "flet>=0.86.5",
    "flet-image-viewer @ git+https://github.com/zaim-tech/flet-image-viewer.git",
]

Usage

import flet as ft

from flet_image_viewer import FletImageViewer


def main(page: ft.Page):
    page.title = "Image viewer example"
    page.add(
        FletImageViewer(
            src="https://picsum.photos/900/600",
            show_close_button=True,
            BoxFit=ft.BoxFit.CONTAIN,
            min_scale=1.0,
            max_scale=4.0,
            expand=True,
        )
    )


ft.run(main)

The src property accepts an image URL or a local file path. For example:

base = os.path.dirname(os.path.abspath(__file__))
image = os.path.join(base, "assets/photo.jpg")
FletImageViewer(src=image)

Swipeable gallery

Use FletMultiViewer to display multiple images. The index property selects the image shown first, starting at 0.

import flet as ft

from flet_image_viewer import FletMultiViewer


def main(page: ft.Page):
    page.add(
        FletMultiViewer(
            src=[
                "https://picsum.photos/id/10/900/600",
                "https://picsum.photos/id/20/900/600",
                "https://picsum.photos/id/30/900/600",
            ],
            viewer_id="photo-gallery",
            index=0,
            BoxFit=ft.BoxFit.CONTAIN,
            overlay=ft.Container(
                content=ft.Text("Swipe to view more"),
                bgcolor=ft.Colors.with_opacity(0.75, ft.Colors.BLACK),
                padding=10,
            ),
            on_long_press=lambda event: print("Image long-pressed"),
            on_double_tap=lambda event: print("Image double-tapped"),
            expand=True,
        )
    )


ft.run(main)

Control properties

Property Type Default Description
src str / list required Image URL or local path, or a list of URLs and paths for FletMultiViewer.
viewer_id str required for FletMultiViewer Identifier for the multi-image viewer.
index int 0 Initial image index for FletMultiViewer.
show_close_button bool False Shows a close button on FletImageViewer.
BoxFit ft.BoxFit \\| None None Controls how the image fits inside the viewer.
overlay ft.Control \\| None None Flet control displayed over the image viewer.
min_scale / max_scale float \\| None None Minimum and maximum zoom levels.
on_long_press event handler None Called when the image is long-pressed.
on_double_tap event handler None Called when the image is double-tapped.

Events

Register handlers directly on either viewer:

def handle_double_tap(event: ft.ControlEvent):
    print("Viewer double-tapped")


viewer = FletImageViewer(
    src="https://picsum.photos/900/600",
    on_double_tap=handle_double_tap,
)

Platform support

The extension supports all Flet platforms except Web:

Platform Support
Android Supported
iOS Supported
Linux Supported
macOS Supported
Windows Supported
Web Not supported

Build and run

For desktop development, build the client once and then use flet run:

flet build windows
flet run

Rebuild the client when the extension's Dart code changes. Python-only changes can be picked up with the normal Flet development workflow after the extension has been built.

Build the example

The example application is in examples/flet_image_viewer_example/:

cd examples/flet_image_viewer_example
flet build windows
flet run

Replace windows with another supported desktop or mobile target.

Documentation

See the complete API documentation for the generated control reference.

Development

The project follows Flet's extension structure:

src/flet_image_viewer/               Python controls
src/flutter/flet_image_viewer/       Native Flutter extension
examples/flet_image_viewer_example/  Sample Flet application
docs/                                API documentation

License

See LICENSE.


Made with ❤️ by Zaim Sheali

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flet_image_viewer-0.1.1.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flet_image_viewer-0.1.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file flet_image_viewer-0.1.1.tar.gz.

File metadata

  • Download URL: flet_image_viewer-0.1.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for flet_image_viewer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b30b2256b25e3cb38bbc25bb025f01bc3d286dd03526155a51f76ef807fe0516
MD5 56a9f7c954cc81f1627432f4bc1e86f9
BLAKE2b-256 b3f0c65adc775765dbbb6cc8f20dad098789364a2ceaa01d864694cfe792dabd

See more details on using hashes here.

Provenance

The following attestation bundles were made for flet_image_viewer-0.1.1.tar.gz:

Publisher: publish.yml on zaim-tech/flet-image-viewer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flet_image_viewer-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for flet_image_viewer-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5cc59e2b25f1580812875fed6f008bbda30ae1c2094b28d01189a5d59daf8532
MD5 98074d5c43d737644be8ab2f5a295b4b
BLAKE2b-256 ea006c179506271c26b252095c64f0813a14c437c09cdfc2890f91d2f98f8f38

See more details on using hashes here.

Provenance

The following attestation bundles were made for flet_image_viewer-0.1.1-py3-none-any.whl:

Publisher: publish.yml on zaim-tech/flet-image-viewer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page