flutter_zoom_level 0.0.1
flutter_zoom_level: ^0.0.1 copied to clipboard
A Flutter plugin to get the screen zoom level and listen to zoom level changes on Android and iOS.
flutter_zoom_level #
A Flutter plugin that provides the current display zoom level (device pixel ratio) and allows listening to changes in zoom/display metrics (e.g., when the user changes display size or accessibility settings).
Features #
- Get current screen zoom level (device pixel ratio)
- Listen for zoom level changes on Android and iOS
- Supports real devices and emulators
- Easy-to-use simple API
Installation #
Add to your pubspec.yaml:
dependencies:
flutter_zoom_level: ^0.0.1
Run:
flutter pub get
⸻
Usage
Import the plugin:
import 'package:flutter_zoom_level/flutter_zoom_level.dart';
Get current zoom level:
double zoomLevel = await FlutterZoomLevel.getZoomLevel();
print('Current zoom level: $zoomLevel');
Listen to zoom level changes:
FlutterZoomLevel.onZoomLevelChanged.listen((double zoom) {
print('Zoom level changed: $zoom');
});
⸻
Example
import 'package:flutter/material.dart';
import 'package:flutter_zoom_level/flutter_zoom_level.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(home: ZoomLevelPage());
}
}
class ZoomLevelPage extends StatefulWidget {
const ZoomLevelPage({super.key});
@override
State<ZoomLevelPage> createState() => _ZoomLevelPageState();
}
class _ZoomLevelPageState extends State<ZoomLevelPage> with WidgetsBindingObserver {
double? zoomLevel;
@override
void initState() {
super.initState();
_getZoomLevel();
WidgetsBinding.instance.addObserver(this);
}
@override
void didChangeMetrics() {
_getZoomLevel();
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
Future<void> _getZoomLevel() async {
try {
final zoom = await FlutterZoomLevel.getZoomLevel();
setState(() {
zoomLevel = zoom;
});
} catch (e) {
debugPrint('Error getting zoom level: $e');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Zoom Level')),
body: Center(
child: Text(
zoomLevel != null ? 'Zoom: $zoomLevel' : 'Loading...',
style: const TextStyle(fontSize: 24),
),
),
);
}
}
⸻
Supported Platforms
• Android
• iOS
⸻
License
MIT ©
⸻
Contributions
Issues, suggestions, and pull requests are welcome!
See issues.
⸻