ZoomViewer

pub package License: MIT style: flutter_lints

A powerful and easy-to-use Flutter package that makes any widget zoomable with pinch and pan gestures, just like zooming images in a gallery. Perfect for image viewers, charts, diagrams, and any interactive content that needs zoom functionality.

โœจ Features

  • ๐Ÿ” Universal Zoom - Works with ANY Flutter widget (Images, Containers, Custom Widgets, Charts, etc.)
  • ๐Ÿ‘Œ Pinch Gesture - Intuitive pinch to zoom in/out
  • ๐Ÿ–๏ธ Pan Support - Smoothly pan around when zoomed
  • ๐Ÿ‘† Double Tap - Quick zoom toggle with double tap
  • โš™๏ธ Highly Customizable - Configure min/max scale, animations, and more
  • ๐ŸŽจ Smooth Animations - Beautiful, configurable animations
  • ๐Ÿ“Š Real-time Callbacks - Get notified when zoom level changes
  • ๐ŸŽฏ Production Ready - Well-tested and documented
  • ๐Ÿ“ฑ Cross Platform - Works on iOS, Android, Web, Windows, macOS, and Linux

๐Ÿ“ฆ Installation

Add this to your package's pubspec.yaml file:

dependencies:
  zoom_viewer: ^1.0.3

or

flutter pub add zoom_viewer

Then run:

flutter pub get

๐Ÿš€ Quick Start

Import the package:

import 'package:zoomable_widget/zoomable_widget.dart';

Wrap any widget with ZoomViewer:

ZoomViewer(
  child: Image.network('https://example.com/image.jpg'),
)

That's it! Your widget is now zoomable. ๐ŸŽ‰

๐Ÿ“– Usage Examples

Basic Image Viewer

ZoomViewer(
  minScale: 0.5,
  maxScale: 4.0,
  child: Image.asset('assets/photo.jpg'),
)

Custom Container

ZoomViewer(
  minScale: 0.5,
  maxScale: 4.0,
  backgroundColor: Colors.black,
  child: Container(
    width: 300,
    height: 300,
    decoration: BoxDecoration(
      color: Colors.blue,
      borderRadius: BorderRadius.circular(20),
    ),
    child: Center(
      child: Text(
        'Zoom Me!',
        style: TextStyle(
          color: Colors.white,
          fontSize: 24,
          fontWeight: FontWeight.bold,
        ),
      ),
    ),
  ),
)

With Zoom Callback

ZoomViewer(
  minScale: 0.5,
  maxScale: 5.0,
  onScaleChanged: (scale) {
    print('Current zoom level: ${scale.toStringAsFixed(2)}x');
  },
  child: YourCustomWidget(),
)

Complex Widget Example

ZoomViewer(
  minScale: 0.3,
  maxScale: 3.0,
  initialScale: 1.0,
  enablePan: true,
  resetOnDoubleTap: true,
  backgroundColor: Colors.grey[200],
  animationDuration: Duration(milliseconds: 300),
  clipBehavior: true,
  onScaleChanged: (scale) {
    setState(() {
      currentZoom = scale;
    });
  },
  child: YourComplexWidget(),
)
PageView.builder(
  itemCount: images.length,
  itemBuilder: (context, index) {
    return ZoomViewer(
      minScale: 0.5,
      maxScale: 4.0,
      child: Image.network(images[index]),
    );
  },
)

๐ŸŽ›๏ธ Configuration Parameters

Parameter Type Default Description
child Widget required The widget to make zoomable
minScale double 0.5 Minimum zoom scale (must be > 0 and โ‰ค 1.0)
maxScale double 4.0 Maximum zoom scale (must be โ‰ฅ 1.0)
initialScale double 1.0 Initial zoom scale (between min and max)
enablePan bool true Enable/disable panning gesture
backgroundColor Color? null Background color behind the widget
onScaleChanged ValueChanged<double>? null Callback fired when zoom level changes
resetOnDoubleTap bool true Reset zoom on double tap
animationDuration Duration 300ms Duration for zoom animations
clipBehavior bool true Whether to clip the child widget

๐ŸŽฎ Gestures

  • Pinch: Zoom in/out with two fingers
  • Pan: Move around when zoomed in (single finger drag)
  • Double Tap: Toggle between zoomed and initial state

๐Ÿ’ก Real-World Use Cases

  • ๐Ÿ“ธ Photo Galleries - Create Instagram-like image viewers
  • ๐Ÿ“Š Charts & Graphs - Allow users to zoom into data visualizations
  • ๐Ÿ—บ๏ธ Maps & Diagrams - Interactive map exploration
  • ๐Ÿ“„ Document Viewers - PDF-like zoom functionality
  • ๐ŸŽจ Design Tools - Zoom into design mockups or blueprints
  • ๐ŸŽ“ Educational Apps - Zoom into detailed diagrams and illustrations
  • ๐Ÿ—๏ธ Floor Plans - Interactive building plan viewers
  • ๐Ÿงฉ Puzzle Games - Zoom interface for detailed game boards

๐Ÿƒ Running the Example

The package includes a complete example app with three different demos:

cd example
flutter pub get
flutter run

The example includes:

  1. Simple Container - Basic zoomable colored box
  2. Gradient Box - Beautiful gradient design with zoom
  3. Complex Widget - Full user profile card with zoom

๐Ÿ“ฑ Platform Support

Platform Supported
Android โœ…
iOS โœ…
Web โœ…
Windows โœ…
macOS โœ…
Linux โœ…

๐Ÿงช Testing

The package includes comprehensive unit tests. Run them with:

flutter test

๐Ÿค Contributing

Contributions are welcome! Here's how you can help:

  1. ๐Ÿ› Report bugs and issues
  2. ๐Ÿ’ก Suggest new features
  3. ๐Ÿ“ Improve documentation
  4. ๐Ÿ”ง Submit pull requests

Please read CONTRIBUTING.md for details on our code of conduct and development process.

๐Ÿ“‹ Changelog

See CHANGELOG.md for a detailed list of changes in each version.

๐Ÿ› Issues

If you encounter any issues, please file them on our issue tracker.

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ‘จโ€๐Ÿ’ป Author

Abubakar (AbubakrFlutter)

โญ Show Your Support

If you like this package, please give it a โญ on GitHub and a ๐Ÿ‘ on pub.flutter-io.cn!

๐Ÿ™ Acknowledgments

Thanks to the Flutter team for creating such an amazing framework and to all contributors who help make this package better!


Made with โค๏ธ for the Flutter community

Libraries

zoom_viewer