flutter_orientation_manager 1.0.2
flutter_orientation_manager: ^1.0.2 copied to clipboard
A Flutter plugin for managing device orientation with real-time orientation change detection.
Flutter Orientation Manager #
A comprehensive Flutter plugin for managing device orientation with real-time orientation change detection.
Features #
- 🔄 Real-time orientation change detection
- 🔒 Lock orientation to portrait or landscape
- 🎯 Toggle between orientations programmatically
- 📱 Cross-platform support (iOS & Android)
- 🚀 Easy to integrate and use
- 💪 Built with native performance
Getting Started #
iOS Setup #
No additional setup required for iOS.
Android Setup #
No additional setup required for Android.
Usage #
Import the package #
import 'package:flutter_orientation_manager/flutter_orientation_manager.dart';
Listen to orientation changes #
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_orientation_manager/flutter_orientation_manager.dart';
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
StreamSubscription<Orientation>? _orientationSubscription;
Orientation _currentOrientation = Orientation.portrait;
@override
void initState() {
super.initState();
// Listen to orientation changes
_orientationSubscription = FlutterOrientationManager.orientationStream.listen((newOrientation) {
setState(() {
_currentOrientation = newOrientation;
});
print('Orientation changed: $newOrientation');
});
}
@override
void dispose() {
_orientationSubscription?.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Orientation Manager Example'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Current Orientation:',
style: TextStyle(fontSize: 18),
),
Text(
_currentOrientation == Orientation.portrait ? 'Portrait' : 'Landscape',
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
),
SizedBox(height: 20),
ElevatedButton(
onPressed: FlutterOrientationManager.toggleOrientation,
child: Text('Toggle Orientation'),
),
ElevatedButton(
onPressed: FlutterOrientationManager.lockOrientation,
child: Text('Lock Current Orientation'),
),
ElevatedButton(
onPressed: FlutterOrientationManager.enableAutoRotation,
child: Text('Enable Auto Rotation'),
),
],
),
),
),
);
}
}
Available Methods #
Orientation Detection
// Get current orientation
Orientation current = FlutterOrientationManager.getCurrentOrientation();
// Check if portrait
bool isPortrait = FlutterOrientationManager.isPortrait;
// Check if landscape
bool isLandscape = FlutterOrientationManager.isLandscape;
// Listen to orientation changes
Stream<Orientation> orientationStream = FlutterOrientationManager.orientationStream;
Orientation Control
// Toggle between portrait and landscape
FlutterOrientationManager.toggleOrientation();
// Lock current orientation
FlutterOrientationManager.lockOrientation();
// Enable automatic rotation
FlutterOrientationManager.enableAutoRotation();
// Force to portrait
FlutterOrientationManager.resetToPortrait();
// Force to landscape
FlutterOrientationManager.forceToLandscape();
Example #
See the example directory for a complete sample app demonstrating all features.
API Reference #
FlutterOrientationManager #
Static Properties
isPortrait→bool: Returns true if device is in portrait modeisLandscape→bool: Returns true if device is in landscape modeorientationStream→Stream<Orientation>: Stream of orientation changes
Static Methods
getCurrentOrientation()→Orientation: Get current device orientationtoggleOrientation()→void: Toggle between portrait and landscapelockOrientation()→void: Lock the current orientationenableAutoRotation()→void: Enable automatic rotationresetToPortrait()→void: Force device to portrait modeforceToLandscape()→void: Force device to landscape mode
Platform Support #
| Platform | Support |
|---|---|
| Android | ✅ |
| iOS | ✅ |
| Web | ❌ |
| macOS | ❌ |
| Windows | ❌ |
| Linux | ❌ |
Contributing #
Contributions are welcome! Please feel free to submit a Pull Request.
License #
This project is licensed under the MIT License - see the LICENSE file for details.
Support #
If you like this package, please give it a ⭐ on GitHub and pub.dev!