Track, nyomkövetés hozzáadása
This commit is contained in:
@@ -0,0 +1,259 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
|
||||
import '../controllers/tracking_controller.dart';
|
||||
import '../../../../models/track.dart';
|
||||
|
||||
/// Mentett track-ek listája megtekintési és export lehetőséggel.
|
||||
class TrackListView extends GetView<TrackingController> {
|
||||
const TrackListView({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Mentett track-ek'),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh),
|
||||
onPressed: controller.loadSavedTracks,
|
||||
)
|
||||
],
|
||||
),
|
||||
body: Obx(() {
|
||||
final tracks = controller.savedTracks;
|
||||
if (tracks.isEmpty) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.route, size: 64, color: Colors.grey.shade300),
|
||||
const SizedBox(height: 12),
|
||||
Text('Még nincs mentett nyomvonal',
|
||||
style: TextStyle(color: Colors.grey.shade500)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return ListView.separated(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
itemCount: tracks.length,
|
||||
separatorBuilder: (_, __) => const Divider(height: 1),
|
||||
itemBuilder: (context, i) => _TrackTile(track: tracks[i]),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _TrackTile extends GetView<TrackingController> {
|
||||
final Track track;
|
||||
const _TrackTile({required this.track});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final statusColor = switch (track.status) {
|
||||
TrackStatus.recording => Colors.red,
|
||||
TrackStatus.paused => Colors.orange,
|
||||
TrackStatus.finished => Colors.green,
|
||||
};
|
||||
|
||||
return Dismissible(
|
||||
key: ValueKey(track.id),
|
||||
direction: DismissDirection.endToStart,
|
||||
confirmDismiss: (_) => _confirm(context),
|
||||
onDismissed: (_) => controller.deleteTrack(track.id!),
|
||||
background: Container(
|
||||
color: Colors.red,
|
||||
alignment: Alignment.centerRight,
|
||||
padding: const EdgeInsets.only(right: 20),
|
||||
child: const Icon(Icons.delete, color: Colors.white),
|
||||
),
|
||||
child: ListTile(
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: statusColor.withOpacity(0.15),
|
||||
child: Icon(Icons.route, color: statusColor),
|
||||
),
|
||||
title: Text(track.name,
|
||||
style: const TextStyle(fontWeight: FontWeight.w600)),
|
||||
subtitle: Text(
|
||||
'${track.distanceFormatted} · ${track.durationFormatted}'
|
||||
' · ${track.pointCount} pont\n${track.source}',
|
||||
),
|
||||
isThreeLine: true,
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.map_outlined),
|
||||
tooltip: 'Megtekintés',
|
||||
onPressed: () => Get.to(() => _TrackPreviewView(track: track)),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.share),
|
||||
tooltip: 'GPX export',
|
||||
onPressed: () => controller.exportTrack(track),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<bool> _confirm(BuildContext context) async {
|
||||
return await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (_) => AlertDialog(
|
||||
title: const Text('Track törlése'),
|
||||
content: Text('"${track.name}" törlése visszavonohatalan.'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, false),
|
||||
child: const Text('Mégse')),
|
||||
FilledButton.tonal(
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: Colors.red.shade50),
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
child: const Text('Törlés',
|
||||
style: TextStyle(color: Colors.red))),
|
||||
],
|
||||
),
|
||||
) ??
|
||||
false;
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Track előnézeti térkép ──────────────────────────────────────────────────
|
||||
|
||||
class _TrackPreviewView extends GetView<TrackingController> {
|
||||
final Track track;
|
||||
const _TrackPreviewView({required this.track});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(track.name),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.share),
|
||||
onPressed: () => controller.exportTrack(track),
|
||||
)
|
||||
],
|
||||
),
|
||||
body: FutureBuilder<List<LatLng>>(
|
||||
future: controller.loadTrackPoints(track.id!),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
if (snapshot.hasError) {
|
||||
return Center(child: Text('Hiba: ${snapshot.error}'));
|
||||
}
|
||||
final points = snapshot.data ?? [];
|
||||
if (points.isEmpty) {
|
||||
return const Center(child: Text('Nincs megjeleníthető pont.'));
|
||||
}
|
||||
|
||||
// Bounding box számítás automatikus zoom-hoz
|
||||
final lats = points.map((p) => p.latitude).toList();
|
||||
final lons = points.map((p) => p.longitude).toList();
|
||||
final center = LatLng(
|
||||
(lats.reduce((a, b) => a + b)) / lats.length,
|
||||
(lons.reduce((a, b) => a + b)) / lons.length,
|
||||
);
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: FlutterMap(
|
||||
options: MapOptions(
|
||||
initialCenter: center,
|
||||
initialZoom: 14,
|
||||
initialCameraFit: CameraFit.coordinates(
|
||||
coordinates: points,
|
||||
padding: const EdgeInsets.all(40),
|
||||
),
|
||||
),
|
||||
children: [
|
||||
TileLayer(
|
||||
urlTemplate:
|
||||
'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||
userAgentPackageName: 'hu.app_dev.terepi_seged',
|
||||
),
|
||||
PolylineLayer(
|
||||
polylines: [
|
||||
Polyline(
|
||||
points: points,
|
||||
color: Colors.blue.shade700,
|
||||
strokeWidth: 4.0,
|
||||
borderColor: Colors.blue.shade200,
|
||||
borderStrokeWidth: 1.5,
|
||||
),
|
||||
],
|
||||
),
|
||||
MarkerLayer(
|
||||
markers: [
|
||||
Marker(
|
||||
point: points.first,
|
||||
child: const Icon(Icons.flag,
|
||||
color: Colors.green, size: 28),
|
||||
),
|
||||
Marker(
|
||||
point: points.last,
|
||||
child: const Icon(Icons.flag,
|
||||
color: Colors.red, size: 28),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Statisztika sáv alul
|
||||
Container(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
24, 12, 24, 12 + MediaQuery.of(context).padding.bottom),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
_InfoChip(
|
||||
icon: Icons.straighten, text: track.distanceFormatted),
|
||||
_InfoChip(
|
||||
icon: Icons.timer_outlined,
|
||||
text: track.durationFormatted),
|
||||
_InfoChip(
|
||||
icon: Icons.location_on_outlined,
|
||||
text: '${track.pointCount} pont'),
|
||||
_InfoChip(icon: Icons.sensors, text: track.source),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _InfoChip extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final String text;
|
||||
const _InfoChip({required this.icon, required this.text});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(icon, size: 15, color: Theme.of(context).colorScheme.primary),
|
||||
const SizedBox(width: 4),
|
||||
Text(text, style: const TextStyle(fontSize: 13)),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,390 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
|
||||
import '../controllers/tracking_controller.dart';
|
||||
import '../../../../models/track.dart';
|
||||
import 'track_list_view.dart';
|
||||
|
||||
class TrackingView extends GetView<TrackingController> {
|
||||
const TrackingView({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container();
|
||||
return Scaffold(
|
||||
extendBody: true,
|
||||
appBar: AppBar(
|
||||
title: const Text('Nyomvonal'),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.list_alt),
|
||||
tooltip: 'Mentett track-ek',
|
||||
onPressed: () => Get.to(() => const TrackListView()),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Stack(
|
||||
children: [
|
||||
_LiveMap(),
|
||||
_StatsPanel(),
|
||||
],
|
||||
),
|
||||
bottomNavigationBar: _ControlBar(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Térkép ─────────────────────────────────────────────────────────────────
|
||||
|
||||
class _LiveMap extends GetView<TrackingController> {
|
||||
const _LiveMap();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final mapController = MapController();
|
||||
|
||||
return Obx(() {
|
||||
final points = controller.livePoints;
|
||||
final center = points.isNotEmpty
|
||||
? points.last
|
||||
: const LatLng(47.5, 19.0); // Magyarország közepe
|
||||
|
||||
// Középre követ rögzítés közben
|
||||
if (controller.isRecording.value && points.isNotEmpty) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
mapController.move(points.last, mapController.camera.zoom);
|
||||
});
|
||||
}
|
||||
|
||||
return FlutterMap(
|
||||
mapController: mapController,
|
||||
options: MapOptions(
|
||||
initialCenter: center,
|
||||
initialZoom: 15.0,
|
||||
interactionOptions: const InteractionOptions(
|
||||
flags: InteractiveFlag.all,
|
||||
),
|
||||
),
|
||||
children: [
|
||||
TileLayer(
|
||||
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||
userAgentPackageName: 'hu.app_dev.terepi_seged',
|
||||
),
|
||||
if (points.length >= 2)
|
||||
PolylineLayer(
|
||||
polylines: [
|
||||
Polyline(
|
||||
points: points,
|
||||
color: Colors.blue.shade700,
|
||||
strokeWidth: 4.0,
|
||||
borderColor: Colors.blue.shade200,
|
||||
borderStrokeWidth: 1.5,
|
||||
),
|
||||
],
|
||||
),
|
||||
if (points.isNotEmpty)
|
||||
MarkerLayer(
|
||||
markers: [
|
||||
// Kezdőpont
|
||||
Marker(
|
||||
point: points.first,
|
||||
child: const Icon(Icons.flag, color: Colors.green, size: 28),
|
||||
),
|
||||
// Aktuális pozíció
|
||||
Marker(
|
||||
point: points.last,
|
||||
child: _PulsingDot(
|
||||
color:
|
||||
controller.isPaused.value ? Colors.orange : Colors.blue,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Pulzáló pont az aktuális pozícióhoz.
|
||||
class _PulsingDot extends StatefulWidget {
|
||||
final Color color;
|
||||
const _PulsingDot({required this.color});
|
||||
|
||||
@override
|
||||
State<_PulsingDot> createState() => _PulsingDotState();
|
||||
}
|
||||
|
||||
class _PulsingDotState extends State<_PulsingDot>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late AnimationController _anim;
|
||||
late Animation<double> _scale;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_anim = AnimationController(
|
||||
vsync: this, duration: const Duration(milliseconds: 1000))
|
||||
..repeat(reverse: true);
|
||||
_scale = Tween(begin: 0.8, end: 1.3)
|
||||
.animate(CurvedAnimation(parent: _anim, curve: Curves.easeInOut));
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_anim.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ScaleTransition(
|
||||
scale: _scale,
|
||||
child: Container(
|
||||
width: 18,
|
||||
height: 18,
|
||||
decoration: BoxDecoration(
|
||||
color: widget.color,
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: Colors.white, width: 2),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: widget.color.withOpacity(0.5),
|
||||
blurRadius: 8,
|
||||
spreadRadius: 2)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Statisztika panel ────────────────────────────────────────────────────────
|
||||
|
||||
class _StatsPanel extends GetView<TrackingController> {
|
||||
const _StatsPanel();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Obx(() {
|
||||
if (!controller.isRecording.value && controller.livePoints.isEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
return Positioned(
|
||||
top: 12,
|
||||
left: 12,
|
||||
right: 12,
|
||||
child: Card(
|
||||
elevation: 4,
|
||||
shape:
|
||||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
color: Theme.of(context).colorScheme.surface.withOpacity(0.92),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
_Stat(
|
||||
icon: Icons.timer_outlined,
|
||||
label: 'Idő',
|
||||
value: controller.elapsedFormatted.value,
|
||||
),
|
||||
_Divider(),
|
||||
_Stat(
|
||||
icon: Icons.straighten,
|
||||
label: 'Távolság',
|
||||
value: _formatDist(controller.sessionDistance.value),
|
||||
),
|
||||
_Divider(),
|
||||
_Stat(
|
||||
icon: Icons.speed,
|
||||
label: 'Sebesség',
|
||||
value:
|
||||
'${controller.currentSpeedKmh.value.toStringAsFixed(1)} km/h',
|
||||
),
|
||||
_Divider(),
|
||||
_Stat(
|
||||
icon: Icons.location_on_outlined,
|
||||
label: 'Pontok',
|
||||
value: controller.livePoints.length.toString(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
String _formatDist(double m) {
|
||||
if (m < 1000) return '${m.toStringAsFixed(0)} m';
|
||||
return '${(m / 1000).toStringAsFixed(2)} km';
|
||||
}
|
||||
}
|
||||
|
||||
class _Stat extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final String label;
|
||||
final String value;
|
||||
const _Stat({required this.icon, required this.label, required this.value});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(icon, size: 16, color: Theme.of(context).colorScheme.primary),
|
||||
const SizedBox(height: 2),
|
||||
Text(value,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 15)),
|
||||
Text(label,
|
||||
style: TextStyle(fontSize: 10, color: Colors.grey.shade600)),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Divider extends StatelessWidget {
|
||||
const _Divider();
|
||||
@override
|
||||
Widget build(BuildContext context) =>
|
||||
Container(height: 36, width: 1, color: Colors.grey.shade300);
|
||||
}
|
||||
|
||||
// ─── Vezérlő sáv ────────────────────────────────────────────────────────────
|
||||
|
||||
class _ControlBar extends GetView<TrackingController> {
|
||||
const _ControlBar();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Obx(() {
|
||||
final recording = controller.isRecording.value;
|
||||
final paused = controller.isPaused.value;
|
||||
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.12),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, -2))
|
||||
],
|
||||
),
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
24, 12, 24, 12 + MediaQuery.of(context).padding.bottom),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
if (!recording) ...[
|
||||
// ── Nincs aktív track ──
|
||||
_RoundButton(
|
||||
icon: Icons.fiber_manual_record,
|
||||
label: 'Indítás',
|
||||
color: Colors.red,
|
||||
onTap: () => controller.startRecording(),
|
||||
),
|
||||
] else ...[
|
||||
// ── Aktív track ──
|
||||
_RoundButton(
|
||||
icon: paused ? Icons.play_arrow : Icons.pause,
|
||||
label: paused ? 'Folytatás' : 'Szünet',
|
||||
color: Colors.orange,
|
||||
onTap: paused
|
||||
? controller.resumeRecording
|
||||
: controller.pauseRecording,
|
||||
),
|
||||
// Nagy Stop gomb középen
|
||||
GestureDetector(
|
||||
onTap: () => _confirmStop(context),
|
||||
child: Container(
|
||||
width: 68,
|
||||
height: 68,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.red,
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.red.withOpacity(0.4),
|
||||
blurRadius: 12,
|
||||
spreadRadius: 2)
|
||||
],
|
||||
),
|
||||
child: const Icon(Icons.stop, color: Colors.white, size: 32),
|
||||
),
|
||||
),
|
||||
_RoundButton(
|
||||
icon: Icons.share,
|
||||
label: 'Export',
|
||||
color: Colors.blue,
|
||||
onTap: () {
|
||||
final t = controller.currentTrack.value;
|
||||
if (t != null) controller.exportTrack(t);
|
||||
},
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _confirmStop(BuildContext context) async {
|
||||
final ok = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (_) => AlertDialog(
|
||||
title: const Text('Track leállítása'),
|
||||
content: const Text(
|
||||
'Leállítja a rögzítést? A track automatikusan mentésre kerül.'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, false),
|
||||
child: const Text('Mégse')),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
child: const Text('Leállítás')),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (ok == true) controller.stopRecording();
|
||||
}
|
||||
}
|
||||
|
||||
class _RoundButton extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final String label;
|
||||
final Color color;
|
||||
final VoidCallback onTap;
|
||||
const _RoundButton(
|
||||
{required this.icon,
|
||||
required this.label,
|
||||
required this.color,
|
||||
required this.onTap});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: 52,
|
||||
height: 52,
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.12),
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: color, width: 1.5),
|
||||
),
|
||||
child: Icon(icon, color: color, size: 26),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(label, style: TextStyle(fontSize: 11, color: color)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user