Device Orientation Detector
A Flutter plugin that detects device orientation changes using native Android & iOS sensorsβeven when the app is locked to portrait mode! π
β¨ Features
β
Detects portrait & landscape mode using accelerometer & motion sensors.
β
Works even when screen rotation is locked.
β
Lightweight & efficientβdoesn't drain battery.
β
No special permissions required on Android or iOS.
π¦ Installation
Add this to your pubspec.yaml:
dependencies:
device_orientation_detector: ^1.0.3
Then, run:
flutter pub get
π Usage
import 'package:device_orientation_detector/device_orientation_detector.dart';
void main() {
DeviceOrientationDetector().onOrientationChanged.listen((orientation) {
print('Orientation: $orientation'); // "portrait" or "landscape"
});
}
π± Platform Support
β Android (Uses SensorManager)
β iOS (Uses CoreMotion)
π οΈ How It Works
- On Android, it uses the accelerometer sensor to determine the device's tilt.
- On iOS, it uses CoreMotion to read the device's attitude and detect orientation.
- Even when screen rotation is locked, this plugin detects orientation changes.
π License
This project is licensed under the MIT License. See the LICENSE file for details.