MobilApp/lib/pages/map_survey/presentations/views/map_survey_view.dart

207 lines
6.1 KiB
Dart

import 'dart:io';
import 'dart:math';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter_map_polywidget/flutter_map_polywidget.dart';
import 'package:get/get.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
import 'package:rive/rive.dart';
import 'package:terepi_seged/pages/map_survey/presentations/controllers/map_survey_controller.dart';
import 'package:terepi_seged/pages/map_survey/presentations/views/settings_dialog.dart';
import 'package:terepi_seged/utils/rive_utils.dart';
import 'package:terepi_seged/widgets/coordinate_panel.dart';
import 'package:terepi_seged/widgets/save_point_fab.dart';
import 'package:terepi_seged/widgets/shared_map_widgets.dart';
import 'map_add_point_dialog.dart';
class MapSurveyView extends GetView<MapSurveyController> {
const MapSurveyView({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Stack(children: [
const SharedMapWidget(),
Positioned(
top: 8,
right: 8,
left: 8,
child: CoordinatePanel.fromController(controller),
),
Positioned(top: 8, left: 0, right: 0, child: _ModeSelector()),
Positioned(
bottom: 80,
left: 8,
right: 8,
child: Obx(
() => controller.mode.value == MapSurveyMode.stakeout
? _StakeoutPanel() // ΔY, ΔX, távolság, irányszög
: const SizedBox.shrink(),
),
),
Positioned(
bottom: 16,
right: 16,
child: SavePointFab(controller: controller),
),
]);
}
}
class _ModeSelector extends GetView<MapSurveyController> {
const _ModeSelector();
@override
Widget build(BuildContext context) {
return Obx(() => SegmentedButton<MapSurveyMode>(
segments: const [
ButtonSegment(
value: MapSurveyMode.measure,
icon: Icon(Icons.gps_fixed, size: 16),
label: Text('Bemérés'),
),
ButtonSegment(
value: MapSurveyMode.stakeout,
icon: Icon(Icons.my_location, size: 16),
label: Text('Kitűzés'),
),
],
selected: {controller.mode.value},
onSelectionChanged: (s) => controller.switchMode(s.first),
));
}
}
class _StakeoutPanel extends GetView<MapSurveyController> {
const _StakeoutPanel();
@override
Widget build(BuildContext context) {
return Card(
child: Padding(
padding: const EdgeInsets.all(12),
child: Obx(() {
final onTarget = controller.isOnTarget;
final dy = controller.deltaY;
final dx = controller.deltaX;
final dist = controller.distanceToTarget;
return Column(
mainAxisSize: MainAxisSize.min,
children: [
// Célpont neve
Row(children: [
const Icon(Icons.flag, size: 16, color: Colors.orange),
const SizedBox(width: 6),
Text(controller.targetName.value,
style: const TextStyle(fontWeight: FontWeight.w600)),
const Spacer(),
TextButton(
onPressed: _showTargetPicker,
child: const Text('Változtat'),
),
]),
const Divider(height: 16),
// Eltérések
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_DeltaCell(
label: 'ΔY',
value: dy,
unit: 'm',
),
_DeltaCell(
label: 'ΔX',
value: dx,
unit: 'm',
),
_DeltaCell(
label: 'Táv',
value: dist,
unit: 'm',
alwaysPositive: true,
),
],
),
const SizedBox(height: 8),
// Státusz
Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(vertical: 6),
decoration: BoxDecoration(
color: onTarget
? Colors.green.withOpacity(0.12)
: Colors.orange.withOpacity(0.12),
borderRadius: BorderRadius.circular(8),
),
child: Text(
onTarget
? '✓ Célponton — pont rögzíthető'
: '${controller.distanceToTarget.toStringAsFixed(3)} m a céltól',
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.w500,
color: onTarget ? Colors.green : Colors.orange,
fontSize: 13,
),
),
),
],
);
}),
),
);
}
void _showTargetPicker() {
// Lista a korábban bemért vagy tervezett pontokból
//Get.bottomSheet(const _TargetPickerSheet());
}
}
class _DeltaCell extends StatelessWidget {
final String label;
final double value;
final String unit;
final bool alwaysPositive;
const _DeltaCell({
required this.label,
required this.value,
required this.unit,
this.alwaysPositive = false,
});
@override
Widget build(BuildContext context) {
final display = alwaysPositive ? value.abs() : value;
final prefix = (!alwaysPositive && value > 0) ? '+' : '';
final color = value.abs() < 0.05
? Colors.green
: value.abs() < 0.5
? Colors.orange
: Colors.red;
return Column(
children: [
Text(label, style: const TextStyle(fontSize: 11, color: Colors.grey)),
const SizedBox(height: 2),
Text(
'$prefix${display.toStringAsFixed(3)} $unit',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
color: color,
),
),
],
);
}
}