flutter_device_orientation 0.1.0 copy "flutter_device_orientation: ^0.1.0" to clipboard
flutter_device_orientation: ^0.1.0 copied to clipboard

A Flutter package for calculating device orientation using accelerometer and compass sensors.

example/lib/main.dart

import 'package:flutter_device_orientation/flutter_device_orientation.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(
    const MaterialApp(
      debugShowCheckedModeBanner: false,
      home: OrientationDebugScreen(),
    ),
  );
}

class OrientationDebugScreen extends StatefulWidget {
  const OrientationDebugScreen({super.key});

  @override
  State<OrientationDebugScreen> createState() =>
      _OrientationDebugScreenState();
}

class _OrientationDebugScreenState
    extends State<OrientationDebugScreen> {
  late final DeviceOrientation orientation;

  OrientationData data = OrientationData.zero;

  @override
  void initState() {
    super.initState();

    orientation = DeviceOrientation();

    orientation.stream.listen((value) {
      if (!mounted) return;

      setState(() {
        data = value;
      });
    });

    orientation.start();
  }

  @override
  void dispose() {
    orientation.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Text(
              'DEVICE ORIENTATION',
              style: TextStyle(
                color: Colors.white,
                fontSize: 24,
                fontWeight: FontWeight.bold,
              ),
            ),
            const SizedBox(height: 40),
            _Value(
              name: 'YAW',
              value: data.yaw,
            ),
            _Value(
              name: 'PITCH',
              value: data.pitch,
            ),
            _Value(
              name: 'ROLL',
              value: data.roll,
            ),
          ],
        ),
      ),
    );
  }
}

class _Value extends StatelessWidget {
  final String name;
  final double value;

  const _Value({
    required this.name,
    required this.value,
  });

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(10),
      child: Text(
        '$name: ${value.toStringAsFixed(1)}°',
        style: const TextStyle(
          color: Colors.white,
          fontSize: 22,
        ),
      ),
    );
  }
}
0
likes
160
points
195
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A Flutter package for calculating device orientation using accelerometer and compass sensors.

Repository (GitHub)
View/report issues

Topics

#sensors #orientation #compass #accelerometer #flutter

License

MIT (license)

Dependencies

flutter, flutter_compass, sensors_plus

More

Packages that depend on flutter_device_orientation