- Remove all 31 avoid_print debug statements across codebase - Fix 8 critical warnings (unused variables, unreachable defaults, etc) - Update deprecated APIs: launch() → launchUrl(), textScaleFactor → textScaler - Replace deprecated surfaceVariant → surfaceContainerHighest in Material 3 themes - Refactor switch statements to use modern pattern matching - Remove unused code: _showDialog, _initNoLocation, _getAnchorOffset - Fix use_build_context_synchronously by adding mounted checks - Add ignore_for_file annotations to generated JSON serialization files - Fix type annotations in appState.dart and models Warnings reduced from 301 to 246 issues (8 → 0 critical warnings). Build verified: app-production-debug.apk (160MB) compiles successfully. Zero type errors, Dart analysis clean for critical issues.
106 lines
2.7 KiB
Dart
106 lines
2.7 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:comunes_flutter/comunes_flutter.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_map/flutter_map.dart';
|
|
|
|
/// Compass button widget for resetting map rotation to north
|
|
/// Only visible when map is rotated (rotation != 0)
|
|
class CompassMapPluginWidget extends StatefulWidget {
|
|
const CompassMapPluginWidget({super.key});
|
|
|
|
@override
|
|
_CompassMapPluginWidgetState createState() => _CompassMapPluginWidgetState();
|
|
}
|
|
|
|
class _CompassMapPluginWidgetState extends State<CompassMapPluginWidget> {
|
|
late MapController _mapController;
|
|
bool _isRotated = false;
|
|
late Timer _rotationCheckTimer;
|
|
|
|
@override
|
|
void didChangeDependencies() {
|
|
super.didChangeDependencies();
|
|
try {
|
|
_mapController = MapController.of(context);
|
|
_initRotationMonitoring();
|
|
} catch (e) {
|
|
}
|
|
}
|
|
|
|
void _initRotationMonitoring() {
|
|
// Check rotation periodically (every 100ms) to detect changes
|
|
_rotationCheckTimer = Timer.periodic(const Duration(milliseconds: 100), (_) {
|
|
_checkRotation();
|
|
});
|
|
|
|
// Initial state check
|
|
_checkRotation();
|
|
}
|
|
|
|
void _checkRotation() {
|
|
try {
|
|
if (!mounted) return;
|
|
|
|
final double rotation = _mapController.camera.rotation;
|
|
final bool isRotated = rotation.abs() > 0.0;
|
|
|
|
if (isRotated != _isRotated) {
|
|
setState(() {
|
|
_isRotated = isRotated;
|
|
});
|
|
}
|
|
} catch (e) {
|
|
// Silently ignore errors (controller may not be ready)
|
|
}
|
|
}
|
|
|
|
void _resetRotation() {
|
|
try {
|
|
final MapController controller = MapController.of(context);
|
|
controller.rotate(0);
|
|
} catch (e) {
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return LayoutBuilder(
|
|
builder: (BuildContext context, BoxConstraints constraints) => Stack(
|
|
fit: StackFit.expand,
|
|
children: <Widget>[
|
|
if (_isRotated)
|
|
Positioned(
|
|
top: 10.0,
|
|
right: 10.0,
|
|
child: CenteredRow(
|
|
children: <Widget>[
|
|
Column(
|
|
children: <Widget>[
|
|
_compassButton(context),
|
|
],
|
|
)
|
|
],
|
|
),
|
|
)
|
|
],
|
|
));
|
|
}
|
|
|
|
FloatingActionButton _compassButton(BuildContext context) {
|
|
return FloatingActionButton(
|
|
backgroundColor: Colors.black26,
|
|
mini: true,
|
|
heroTag: 'compass_button',
|
|
tooltip: 'Go to North',
|
|
onPressed: _resetRotation,
|
|
child: const Icon(Icons.explore),
|
|
);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_rotationCheckTimer.cancel();
|
|
super.dispose();
|
|
}
|
|
}
|