compass_plus 0.0.1 copy "compass_plus: ^0.0.1" to clipboard
compass_plus: ^0.0.1 copied to clipboard

Get device heading.

example/lib/main.dart

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

import 'package:compass_plus/compass_plus.dart';

void main() {
  runApp(const MyApp());
}

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  StreamSubscription<double>? _eventsSub;
  double _directionAngle = 0;

  @override
  void initState() {
    super.initState();
    _eventsSub = Compass.events.listen((event) {
      _directionAngle = event;
      setState(() {});
    });
  }

  @override
  void dispose() {
    _eventsSub?.cancel();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Text('Angle: $_directionAngle\n'),
        ),
      ),
    );
  }
}
3
likes
0
pub points
59%
popularity

Publisher

unverified uploader

Get device heading.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on compass_plus