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

A Flutter compass. The heading varies from 0-360, 0 being north.

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
150
pub points
57%
popularity

Publisher

unverified uploader

A Flutter compass. The heading varies from 0-360, 0 being north.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

flutter

More

Packages that depend on compass_plus