Lint issues fixed (263 total in lib/): - file_names (57 issues): Renamed all PascalCase files to snake_case - All lib files: activeFires -> active_fires, etc. - All models: appState -> app_state, fireMapState -> fire_map_state, etc. - All redux files: appActions -> app_actions, appReducer -> app_reducer, etc. - Updated all import statements and exports across the codebase - Fixed unused imports, exports, and references in rebuilt modules Style fixes (16 issues): - prefer_generic_function_type_aliases (2): Updated typedef syntax from old to new - unnecessary_nullable_for_final_variable_declarations (2): Removed ? from non-nullable types - unnecessary_import: Removed duplicate meta/meta import - unnecessary_parenthesis: Removed unnecessary parentheses in expressions - avoid_renaming_method_parameters: Renamed parameter 'o' to 'other' - prefer_const_declarations: Changed final to const for constant values - use_key_in_widget_constructors (3): Added key parameters to widget constructors - sort_child_properties_last (1): Reordered children property to end Verification: - APK builds successfully (146 MB) - Reduced from 106 lint issues to 49 high-priority issues - Total file_names issues: 0 (down from 57) - All imports and exports updated correctly
111 lines
2.9 KiB
Dart
111 lines
2.9 KiB
Dart
import 'dart:async';
|
|
|
|
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 (_) {
|
|
// Ignore - MapController may not be available yet
|
|
}
|
|
}
|
|
|
|
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 (_) {
|
|
// Ignore - MapController may not be available
|
|
}
|
|
}
|
|
|
|
@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: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
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();
|
|
}
|
|
}
|