How to Create a Zoomable Image in Flutter?
Last Updated :
24 Apr, 2025
In Flutter, you can create a zoomable image using the GestureDetector and Transform widgets. The GestureDetector widget can be used to detect pinch gestures on the image, and the Transform widget can be used to apply the zoom transformation to the image.
How to Use:
Container(
child: PhotoView(
imageProvider: AssetImage("assets/img.png"),
)
),
Step By Step Implementation
Step 1: Create a New Project in Android Studio
To set up Flutter Development on Android Studio please refer to Android Studio Setup for Flutter Development, and then create a new project in Android Studio please refer to Creating a Simple Application in Flutter.
Step 2: Add the dependency to your pubspec.yaml file
From the command line:
flutter pub add photo_view
This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):
Import the package
import 'package:photo_view/photo_view.dart';
Step 3: Import the Material Package
Adding a material package that gives us the important functions and calls the runApp method in the main function that will call our application
import 'package:flutter/material.dart';
import 'package:photo_view/photo_view.dart';
void main() {
runApp(RunMyApp());
}
In the above code, runApp method calls the class RunMyApp, Now we have to create it.
Step 4: Creating Stateless Widget
Now we have to make a stateless widget because our application does not go to change its state and then return the MaterialApp widget which allows us the set the title and theme and many more of the application.
Shortcut for creating a stateless or Stateful widget: You can create a stateless widget by just typing three alphabets ‘stl’ and you can see a stateless widget and then hit enter.
class RunMyApp extends StatelessWidget {
const RunMyApp({
super.key
});
@
override
Widget build(BuildContext context) {
return MaterialApp();
}
}
Step 5: Working with Scaffold Widget
Give the home property and there can be a scaffold widget with AppBar and body property. AppBar allows us to give the title of AppBar, color, leading, and trailing icon.
home: Scaffold(
appBar: AppBar(
title: Text('Zoomable Image'),
),
body:
),
Step 6: Using PhotoView
Now we can simply use the PhotoView widget and assign its parameters imageProvider.
body: Container(
child: PhotoView(
imageProvider: AssetImage("assets/img.png"),
)
),
Complete Code:
Dart
import 'package:flutter/material.dart';
import 'package:photo_view/photo_view.dart';
void main() {
runApp(RunMyApp());
}
class RunMyApp extends StatelessWidget {
const RunMyApp({
super.key
});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(primarySwatch: Colors.green),
home: Scaffold(
appBar: AppBar(
title: Text('Zoomable Image'),
),
body: Container(
child: PhotoView(
imageProvider: AssetImage("assets/img.png"),
)
),
),
);
}
}
Output:
Similar Reads
Flutter - Zoom In and Zoom Out an Image
In this article we are using the InteractiveViewer widget in Flutter allows you to create interactive and zoomable widgets. It's commonly used for displaying images, maps, or any content that the user can zoom, and interact with. In this article, we are going to implement the InteractiveViewer widge
3 min read
Flutter - How to Use SVG Image
SVG (Scalable Vector Graphics) is a vector image format that can be used to create high-quality, resolution-independent graphics. In Flutter, you can use SVG images to display vector graphics in your app. To use SVG images in Flutter, you can use the  flutter_svg package to display SVG images in Flu
3 min read
How to Add Firebase into Flutter in a New Way?
Recently Firebase give another option for adding Firebase to Flutter and It is only made for Flutter, As of now we add firebase using the android option for flutter but now we can add using the flutter option that is recently updated by Flutter. Here you can find how to add firebase as an Android in
2 min read
Rounded Corner Image in Flutter
Rounded images or avatars are commonly used in many mobile applications, including those built with Flutter. There are several ways to create rounded images in Flutter, some of which include: Using the ClipRRect widget: As I mentioned earlier, the ClipRRect widget can be used to clip an image and cr
3 min read
Flutter - Upload Images on FireStore Storage
Firestore is a free platform that provides users or developers to test their apps without any cost. However, you have to pay a small amount of money with which you hosted your app and earn money through their services. Firebase or Firestore provides a variety of services: Firestore DatabaseAnalytics
4 min read
How to Create Any Types of Shape Using svg Code in Flutter?
Sometimes it is difficult to make different shapes in Flutter. So no need to worry now You can make any shape if you have svg file or code of that shape. Now you can generate any shape without using any packages. If you don't have the shape in svg file or svg code then you can create it from figma a
3 min read
Flutter - Convert an Image into Base64 String
Base64 encoding is used to convert bytes that have binary or text data into ASCII characters. Encoding prevents the data from getting corrupted when it is transferred or processed through a text-only system. In this article, we will discuss how to convert an image into Base64 String. A sample video
4 min read
How to Create a Desktop Window Application in Flutter?
The Flutter team recently released Flutter version 2.10 with Desktop support. Desktop support allows you to compile Flutter source code to a native Windows, macOS, or Linux desktop app. Flutterâs desktop support also extends to pluginsâyou can install existing plugins that support the Windows, macOS
3 min read
Flutter - Extract Data From an Image to Text
Google ML kit provides many features, one of them is Image to Text Extraction, through which we can simply extract text from an image. To extract text from the image first we need to take an image as input either from the gallery or camera for which we will use 'image_picker: ^1.0.4' (dependency fro
3 min read
Flutter - Create Option Menu for ListView
ListView is the efficient widget to display a list of items. Sometimes we need some options on individual items in the ListView. To create an options menu for a ListView in Flutter, you can use the PopupMenuButton widget along with PopupMenuItem or PopupMenuItemBuilder. This allows you to display a
5 min read