2025-12-30 19:27:25 -07:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import '../connector/meshcore_connector.dart';
|
2026-01-11 17:13:50 -07:00
|
|
|
import '../l10n/l10n.dart';
|
2026-03-02 22:48:19 -05:00
|
|
|
import 'app_logger.dart';
|
2025-12-30 19:27:25 -07:00
|
|
|
|
|
|
|
|
/// Shows a confirmation dialog before disconnecting from the device.
|
|
|
|
|
/// Returns true if user confirmed and disconnect completed, false otherwise.
|
|
|
|
|
Future<bool> showDisconnectDialog(
|
|
|
|
|
BuildContext context,
|
|
|
|
|
MeshCoreConnector connector,
|
|
|
|
|
) async {
|
2026-01-11 17:13:50 -07:00
|
|
|
final l10n = context.l10n;
|
2025-12-30 19:27:25 -07:00
|
|
|
final confirmed = await showDialog<bool>(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (context) => AlertDialog(
|
2026-01-11 17:13:50 -07:00
|
|
|
title: Text(l10n.dialog_disconnect),
|
|
|
|
|
content: Text(l10n.dialog_disconnectConfirm),
|
2025-12-30 19:27:25 -07:00
|
|
|
actions: [
|
|
|
|
|
TextButton(
|
|
|
|
|
onPressed: () => Navigator.pop(context, false),
|
2026-01-11 17:13:50 -07:00
|
|
|
child: Text(l10n.common_cancel),
|
2025-12-30 19:27:25 -07:00
|
|
|
),
|
|
|
|
|
TextButton(
|
|
|
|
|
onPressed: () => Navigator.pop(context, true),
|
2026-01-11 17:13:50 -07:00
|
|
|
child: Text(l10n.common_disconnect),
|
2025-12-30 19:27:25 -07:00
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (confirmed == true) {
|
2026-03-02 22:48:19 -05:00
|
|
|
appLogger.info('Disconnect confirmed from popup', tag: 'Connection');
|
2025-12-30 19:27:25 -07:00
|
|
|
await connector.disconnect();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|