flutter_zoom_level 1.0.0
flutter_zoom_level: ^1.0.0 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 to detect and monitor system zoom level changes on Android and iOS devices.
Installation #
Add to your pubspec.yaml
:
dependencies:
flutter_zoom_level: ^1.0.0
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');
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;
final flutterZoomLevel = FlutterZoomLevel();
@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 License
Contributing #
Issues, suggestions, and pull requests are welcome! See issues.