GnssService osztály és refraktorálás a app_drawer miatt, shellview bevezetés.
This commit is contained in:
@@ -0,0 +1,285 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
|
||||
import '../services/gnss/gnss_connection.dart';
|
||||
import '../services/gnss/gnss_device_service.dart';
|
||||
import '../services/gnss/gnss_service.dart';
|
||||
import 'gnss_device_picker_dialog.dart';
|
||||
|
||||
class AppDrawer extends StatelessWidget {
|
||||
const AppDrawer({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Drawer(
|
||||
// Közvetlenül Column a Drawer-ben — a Drawer maga korlátozott
|
||||
// magasságú (képernyő teljes magassága), így Expanded működik.
|
||||
// SafeArea csak a Header és Footer részeken kell.
|
||||
child: Column(
|
||||
children: [
|
||||
// ── 1. Fejléc — SafeArea csak felül ─────────────────────
|
||||
SafeArea(
|
||||
bottom: false,
|
||||
child: _DrawerHeader(),
|
||||
),
|
||||
|
||||
const Divider(height: 1),
|
||||
|
||||
// ── 2. Scrollozható lista — Expanded tölti ki a helyet ──
|
||||
Expanded(
|
||||
child: ListView(
|
||||
padding: EdgeInsets.zero,
|
||||
children: [
|
||||
// Projekt
|
||||
ListTile(
|
||||
leading: const Icon(Icons.folder_outlined),
|
||||
title: const Text('Aktív projekt'),
|
||||
subtitle: const Text(
|
||||
'Nincs projekt',
|
||||
style: TextStyle(fontSize: 12),
|
||||
),
|
||||
trailing: const Icon(Icons.arrow_forward_ios, size: 14),
|
||||
onTap: () {
|
||||
Get.back();
|
||||
// Get.to(() => const ProjectPickerView());
|
||||
},
|
||||
),
|
||||
|
||||
// GNSS eszköz
|
||||
Obx(() {
|
||||
final device = GnssDeviceService.to.selectedDevice.value;
|
||||
return ListTile(
|
||||
leading: Icon(
|
||||
device?.type == GnssConnectionType.ble
|
||||
? Icons.bluetooth_searching
|
||||
: device?.type == GnssConnectionType.phoneGps
|
||||
? Icons.phone_android
|
||||
: Icons.bluetooth,
|
||||
),
|
||||
title: const Text('GNSS eszköz'),
|
||||
subtitle: Text(
|
||||
device?.name ?? 'Nincs kiválasztva',
|
||||
style: const TextStyle(fontSize: 12),
|
||||
),
|
||||
// Kapcsolat státusz ikon — saját Obx, nem egymásba ágyazva
|
||||
trailing: Obx(() {
|
||||
final connected = GnssService.to.connectionState.value ==
|
||||
GnssConnectionState.connected;
|
||||
return Icon(
|
||||
connected ? Icons.circle : Icons.circle_outlined,
|
||||
size: 12,
|
||||
color: connected ? Colors.green : Colors.grey,
|
||||
);
|
||||
}),
|
||||
onTap: () {
|
||||
Get.back();
|
||||
GnssDevicePickerDialog.show();
|
||||
},
|
||||
);
|
||||
}),
|
||||
|
||||
const Divider(height: 24),
|
||||
|
||||
// ── 3. Beállítások ─────────────────────────────────
|
||||
const _SectionLabel('Beállítások'),
|
||||
|
||||
ListTile(
|
||||
leading: const Icon(Icons.cell_tower),
|
||||
title: const Text('NTRIP'),
|
||||
onTap: () {
|
||||
Get.back();
|
||||
// Get.to(() => const NtripSettingsView());
|
||||
},
|
||||
),
|
||||
|
||||
ListTile(
|
||||
leading: const Icon(Icons.map_outlined),
|
||||
title: const Text('Alaptérkép'),
|
||||
onTap: () {
|
||||
Get.back();
|
||||
// _showBasemapPicker(context);
|
||||
},
|
||||
),
|
||||
|
||||
ListTile(
|
||||
leading: const Icon(Icons.straighten),
|
||||
title: const Text('Koordináta-rendszer'),
|
||||
subtitle: const Text(
|
||||
'EOV',
|
||||
style: TextStyle(fontSize: 12),
|
||||
),
|
||||
onTap: () {
|
||||
Get.back();
|
||||
// Get.to(() => const DisplaySettingsView());
|
||||
},
|
||||
),
|
||||
|
||||
ListTile(
|
||||
leading: const Icon(Icons.volume_up_outlined),
|
||||
title: const Text('Hang és rezgés'),
|
||||
onTap: () {
|
||||
Get.back();
|
||||
// Get.to(() => const FeedbackSettingsView());
|
||||
},
|
||||
),
|
||||
|
||||
const Divider(height: 24),
|
||||
|
||||
// ── 4. Admin (kommentezve, később aktiválható) ──────
|
||||
// Obx(() => AuthService.to.isAdmin
|
||||
// ? Column(children: [...])
|
||||
// : const SizedBox.shrink(),
|
||||
// ),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// ── 5. Lábléc — SafeArea csak alul ──────────────────────
|
||||
const Divider(height: 1),
|
||||
SafeArea(
|
||||
top: false,
|
||||
child: _DrawerFooter(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Fejléc ───────────────────────────────────────────────────────────
|
||||
// Nincs Obx — amíg AuthService ki van kommentelve, nincs reaktív adat.
|
||||
// Ha AuthService bekötésre kerül, akkor kell visszatenni az Obx-et.
|
||||
|
||||
class _DrawerHeader extends StatelessWidget {
|
||||
const _DrawerHeader();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// TODO: Obx(() { final user = AuthService.to.currentUser.value; ... })
|
||||
// amikor az AuthService be lesz kötve.
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(16, 20, 16, 16),
|
||||
child: Row(children: [
|
||||
CircleAvatar(
|
||||
radius: 22,
|
||||
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
|
||||
child: Text(
|
||||
'?', // user?.fullName[0].toUpperCase() ?? '?'
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Theme.of(context).colorScheme.onPrimaryContainer,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Ismeretlen felhasználó',
|
||||
// user?.fullName ?? 'Ismeretlen felhasználó'
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 14,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
Text(
|
||||
'Vendég', // user?.role.label ?? ''
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Lábléc ───────────────────────────────────────────────────────────
|
||||
|
||||
class _DrawerFooter extends StatelessWidget {
|
||||
const _DrawerFooter();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
child: Row(children: [
|
||||
// App verzió
|
||||
FutureBuilder<PackageInfo>(
|
||||
future: PackageInfo.fromPlatform(),
|
||||
builder: (_, snap) => Text(
|
||||
snap.hasData ? 'v${snap.data!.version}' : '',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: Colors.grey.shade500,
|
||||
),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
// Kijelentkezés
|
||||
TextButton.icon(
|
||||
icon: const Icon(Icons.logout, size: 16),
|
||||
label: const Text('Kilépés'),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: Colors.red.shade400,
|
||||
),
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
_confirmSignOut(context);
|
||||
},
|
||||
),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
void _confirmSignOut(BuildContext context) {
|
||||
Get.dialog(AlertDialog(
|
||||
title: const Text('Kijelentkezés'),
|
||||
content: const Text('Biztosan ki szeretnél jelentkezni?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Get.back(),
|
||||
child: const Text('Mégse'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
// AuthService.to.signOut();
|
||||
},
|
||||
child: const Text('Kilépés'),
|
||||
),
|
||||
],
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// ── Szekció felirat ──────────────────────────────────────────────────
|
||||
|
||||
class _SectionLabel extends StatelessWidget {
|
||||
final String text;
|
||||
const _SectionLabel(this.text);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 4),
|
||||
child: Text(
|
||||
text.toUpperCase(),
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.grey.shade500,
|
||||
letterSpacing: 0.8,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,286 @@
|
||||
// lib/widgets/gnss_device_picker_dialog.dart
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../services/gnss/gnss_device_service.dart';
|
||||
import '../services/gnss/gnss_service.dart';
|
||||
|
||||
class GnssDevicePickerDialog extends StatelessWidget {
|
||||
const GnssDevicePickerDialog({super.key});
|
||||
|
||||
static Future<void> show() => Get.dialog(
|
||||
const GnssDevicePickerDialog(),
|
||||
barrierDismissible: true,
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final svc = GnssDeviceService.to;
|
||||
final screenHeight = MediaQuery.of(context).size.height;
|
||||
|
||||
return Dialog(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
// A dialog max a képernyő 80%-át foglalja el
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: screenHeight * 0.80,
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// ── Fejléc — fix, nem scrollozódik ──────────────────
|
||||
Row(children: [
|
||||
const Icon(Icons.sensors),
|
||||
const SizedBox(width: 10),
|
||||
const Expanded(
|
||||
child: Text(
|
||||
'GNSS eszköz kiválasztása',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close, size: 20),
|
||||
onPressed: () => Get.back(),
|
||||
),
|
||||
]),
|
||||
|
||||
const Divider(height: 24),
|
||||
|
||||
// ── Scrollozható tartalom ────────────────────────────
|
||||
Flexible(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Telefon GPS opció
|
||||
_DeviceTile(
|
||||
device: const GnssDevice(
|
||||
address: 'phone',
|
||||
name: 'Telefon GPS',
|
||||
type: GnssConnectionType.phoneGps,
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// BT Serial — párosított eszközök
|
||||
_SectionHeader(
|
||||
title: 'Bluetooth Serial (párosított)',
|
||||
trailing: TextButton.icon(
|
||||
icon: const Icon(Icons.refresh, size: 16),
|
||||
label: const Text('Frissítés'),
|
||||
onPressed: svc.loadPairedBtDevices,
|
||||
),
|
||||
),
|
||||
|
||||
Obx(() {
|
||||
if (svc.pairedBtDevices.isEmpty) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 8),
|
||||
child: Text(
|
||||
'Nincs párosított BT eszköz.',
|
||||
style:
|
||||
TextStyle(color: Colors.grey, fontSize: 13),
|
||||
),
|
||||
);
|
||||
}
|
||||
return Column(
|
||||
children: svc.pairedBtDevices
|
||||
.map((d) => _DeviceTile(device: d))
|
||||
.toList(),
|
||||
);
|
||||
}),
|
||||
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// BLE — keresett eszközök
|
||||
_SectionHeader(
|
||||
title: 'Bluetooth LE',
|
||||
trailing: Obx(
|
||||
() => svc.isScanning.value
|
||||
? Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const SizedBox(
|
||||
width: 14,
|
||||
height: 14,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
TextButton(
|
||||
onPressed: svc.stopBleScan,
|
||||
child: const Text('Stop'),
|
||||
),
|
||||
],
|
||||
)
|
||||
: TextButton.icon(
|
||||
icon: const Icon(Icons.search, size: 16),
|
||||
label: const Text('Keresés'),
|
||||
onPressed: svc.startBleScan,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Obx(() {
|
||||
if (svc.isScanning.value &&
|
||||
svc.scannedBleDevices.isEmpty) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 8),
|
||||
child: Text(
|
||||
'Keresés folyamatban...',
|
||||
style:
|
||||
TextStyle(color: Colors.grey, fontSize: 13),
|
||||
),
|
||||
);
|
||||
}
|
||||
if (svc.scannedBleDevices.isEmpty) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 8),
|
||||
child: Text(
|
||||
'Kattints a "Keresés" gombra.',
|
||||
style:
|
||||
TextStyle(color: Colors.grey, fontSize: 13),
|
||||
),
|
||||
);
|
||||
}
|
||||
return Column(
|
||||
children: svc.scannedBleDevices
|
||||
.map((d) => _DeviceTile(device: d))
|
||||
.toList(),
|
||||
);
|
||||
}),
|
||||
|
||||
// Kis padding alulra a scrollozás végén
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Eszköz sor ──────────────────────────────────────────────────────
|
||||
|
||||
class _DeviceTile extends StatelessWidget {
|
||||
final GnssDevice device;
|
||||
const _DeviceTile({required this.device});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final svc = GnssDeviceService.to;
|
||||
|
||||
return Obx(() {
|
||||
final isSelected = svc.selectedDevice.value?.address == device.address;
|
||||
|
||||
return ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2),
|
||||
leading: CircleAvatar(
|
||||
radius: 18,
|
||||
backgroundColor: isSelected
|
||||
? Colors.blue.withOpacity(0.15)
|
||||
: Colors.grey.withOpacity(0.1),
|
||||
child: Icon(
|
||||
_iconFor(device.type),
|
||||
size: 18,
|
||||
color: isSelected ? Colors.blue : Colors.grey,
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
device.name,
|
||||
style: TextStyle(
|
||||
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
subtitle: Row(children: [
|
||||
_TypeChip(device.typeLabel),
|
||||
if (device.rssi != null) ...[
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
'${device.rssi} dBm',
|
||||
style: const TextStyle(fontSize: 11, color: Colors.grey),
|
||||
),
|
||||
],
|
||||
if (device.type != GnssConnectionType.phoneGps)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 6),
|
||||
child: Text(
|
||||
device.address,
|
||||
style: const TextStyle(fontSize: 10, color: Colors.grey),
|
||||
),
|
||||
),
|
||||
]),
|
||||
trailing: isSelected
|
||||
? const Icon(Icons.check_circle, color: Colors.blue)
|
||||
: null,
|
||||
onTap: () async {
|
||||
await svc.selectDevice(device);
|
||||
Get.back();
|
||||
await GnssService.to.onDeviceChanged(device);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
IconData _iconFor(GnssConnectionType type) => switch (type) {
|
||||
GnssConnectionType.btSerial => Icons.bluetooth,
|
||||
GnssConnectionType.ble => Icons.bluetooth_searching,
|
||||
GnssConnectionType.phoneGps => Icons.phone_android,
|
||||
};
|
||||
}
|
||||
|
||||
// ── Szekció fejléc ───────────────────────────────────────────────────
|
||||
|
||||
class _SectionHeader extends StatelessWidget {
|
||||
final String title;
|
||||
final Widget? trailing;
|
||||
const _SectionHeader({required this.title, this.trailing});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(children: [
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.grey.shade600,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
if (trailing != null) trailing!,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Típus chip ───────────────────────────────────────────────────────
|
||||
|
||||
class _TypeChip extends StatelessWidget {
|
||||
final String label;
|
||||
const _TypeChip(this.label);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 1),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.blue.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
label,
|
||||
style: const TextStyle(fontSize: 10, color: Colors.blue),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user