windrose_compass 1.0.1+1
windrose_compass: ^1.0.1+1 copied to clipboard
A wind rose compass widget for Flutter with 16-point labels, interactive arrow, and hex-grid integration.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:windrose_compass/windrose_compass.dart';
void main() => runApp(const WindRoseExampleApp());
class WindRoseExampleApp extends StatelessWidget {
const WindRoseExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'WindRose Example',
theme: ThemeData(colorSchemeSeed: Colors.blueGrey, useMaterial3: true),
home: const WindRoseExample(),
);
}
}
class WindRoseExample extends StatefulWidget {
const WindRoseExample({super.key});
@override
State<WindRoseExample> createState() => _WindRoseExampleState();
}
class _WindRoseExampleState extends State<WindRoseExample> {
int _windDeg = 0;
int _snapTo = 45;
bool _showDeg = false;
bool _showArrow = true;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('WindRose Demo')),
body: Center(
child: Column(mainAxisSize: MainAxisSize.min, children: [
const Text('Tap the compass to set wind direction:'),
const SizedBox(height: 16),
WindRose(
directionDegrees: _windDeg,
onChanged: (d) => setState(() => _windDeg = d),
size: 150,
snapTo: _snapTo,
showDegrees: _showDeg,
showArrow: _showArrow,
),
const SizedBox(height: 16),
Text('Direction: $windDirLabel ($_windDeg°)',
style: Theme.of(context).textTheme.titleMedium),
Text('Hex dir: ${WindRose.compassToHexDir((_windDeg / 45).round() % 8)}'),
const SizedBox(height: 12),
Wrap(spacing: 8, children: [
DropdownButton<int>(
value: _snapTo,
items: const [
DropdownMenuItem(value: 0, child: Text('none')),
DropdownMenuItem(value: 5, child: Text('5°')),
DropdownMenuItem(value: 15, child: Text('15°')),
DropdownMenuItem(value: 30, child: Text('30°')),
DropdownMenuItem(value: 45, child: Text('45°')),
],
onChanged: (v) { if (v != null) setState(() => _snapTo = v); },
),
FilterChip(label: const Text('Show °'), selected: _showDeg,
onSelected: (v) => setState(() => _showDeg = v)),
FilterChip(label: const Text('Arrow'), selected: _showArrow,
onSelected: (v) => setState(() => _showArrow = v)),
]),
]),
),
);
}
String get windDirLabel {
const labels = ['N','NNE','NE','ENE','E','ESE','SE','SSE',
'S','SSW','SW','WSW','W','WNW','NW','NNW'];
return labels[((_windDeg + 11) % 360 / 22.5).floor() % 16];
}
}