flutter_compass 0.0.2 flutter_compass: ^0.0.2 copied to clipboard
A Flutter compass. The heading varies from 0-360, 0 being north.
import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:flutter_compass/flutter_compass.dart';
void main() => runApp(new MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
double _direction;
@override
void initState() {
super.initState();
FlutterCompass.events.listen((double direction) {
setState(() {
_direction = direction;
});
});
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: const Text('Flutter Compass'),
),
body: new Container(
alignment: Alignment.center,
color: Colors.white,
child: new Transform.rotate(
angle: ((_direction ?? 0) * (math.pi / 180) * -1),
child: new Image.asset('assets/compass.jpg'),
),
),
),
);
}
}