easy_zoom_widget 1.0.0
easy_zoom_widget: ^1.0.0 copied to clipboard
A simple and easy-to-use Flutter package that makes any widget zoomable with pinch, double-tap, and pan gestures. Perfect for images, custom widgets, and any content that needs zoom functionality.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:easy_zoom_widget/easy_zoom_widget.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Easy Zoom Widget Example',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
useMaterial3: true,
),
home: const ExamplePage(),
);
}
}
class ExamplePage extends StatefulWidget {
const ExamplePage({super.key});
@override
State<ExamplePage> createState() => _ExamplePageState();
}
class _ExamplePageState extends State<ExamplePage> {
final ZoomController _controller = ZoomController();
double _currentScale = 1.0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Easy Zoom Widget Example'),
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
),
body: Column(
children: [
// Control panel
Container(
padding: const EdgeInsets.all(16),
color: Colors.grey[200],
child: Column(
children: [
Text(
'Current Scale: ${_currentScale.toStringAsFixed(2)}x',
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 8),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ElevatedButton.icon(
onPressed: () => _controller.zoomOut(),
icon: const Icon(Icons.zoom_out),
label: const Text('Zoom Out'),
),
ElevatedButton.icon(
onPressed: () => _controller.reset(),
icon: const Icon(Icons.refresh),
label: const Text('Reset'),
),
ElevatedButton.icon(
onPressed: () => _controller.zoomIn(),
icon: const Icon(Icons.zoom_in),
label: const Text('Zoom In'),
),
],
),
],
),
),
// Zoomable content
Expanded(
child: EasyZoomWidget(
controller: _controller,
minScale: 0.5,
maxScale: 4.0,
enableDoubleTap: true,
enablePinch: true,
enablePan: true,
onScaleChanged: (scale) {
setState(() {
_currentScale = scale;
});
},
backgroundColor: Colors.white,
child: Center(
child: Container(
width: 300,
height: 300,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.blue.shade300,
Colors.purple.shade300,
Colors.pink.shade300,
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.circular(20),
boxShadow: const [
BoxShadow(
color: Color.fromRGBO(0, 0, 0, 0.2),
blurRadius: 10,
spreadRadius: 2,
),
],
),
child: const Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(
Icons.touch_app,
size: 80,
color: Colors.white,
),
const SizedBox(height: 20),
const Text(
'Pinch to Zoom',
style: TextStyle(
color: Colors.white,
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 10),
const Text(
'Double tap to zoom in/out',
style: TextStyle(
color: Colors.white,
fontSize: 16,
),
),
const SizedBox(height: 5),
const Text(
'Drag to pan when zoomed',
style: TextStyle(
color: Colors.white,
fontSize: 16,
),
),
],
),
),
),
),
),
],
),
);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
}