Files
farolero/lib/servicios/servicio_permisos.dart
T
FreeTLab 56f07364c2
Build & Deploy Farolero / Análisis de código (push) Successful in 13s
Build & Deploy Farolero / Build APK + AAB release (push) Successful in 1m22s
feat: confirm before leaving a game, and fix untranslated strings
Exit confirmation
- A dialog in the app's own style now guards every in-game screen. The safe
  action is the prominent one, so a stray tap keeps you in the game.
- Eleven screens covered, against both the system back gesture and the close
  buttons. The message adapts: a single-device game is lost, a host ends it
  for everyone, a client can rejoin.
- The two screens the host also opens from the manager take a flag so that
  back there just closes them instead of offering to quit.

Translations
- 21 keys were still holding the English text in Arabic, Basque, Hindi,
  Japanese, Korean, Dutch, Polish, Russian, Turkish and both Chinese
  variants: 231 strings, covering the whole multi-device flow, permissions
  and the mode picker. Nothing failed, the app just showed English.
- The permissions dialog was hardcoded in Spanish; it is localized now.
- Portuguese used Spanish gerunds where pt-PT takes "a + infinitive".

Checked what looked untranslated but is not: Animals and Notes are correct
Catalan, Configuration and Vibration correct French, Version correct German.
Those are whitelisted in the new test rather than silently rewritten.

l10n_cobertura_test guards all of it: no missing or orphan keys, no empty
values, no English left outside the whitelist, and placeholders preserved.
2026-07-25 23:59:57 +02:00

86 lines
2.6 KiB
Dart

import 'dart:io';
import 'package:farolero/l10n/generated/app_localizations.dart';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
/// Gestiona los permisos necesarios para Nearby Connections
class ServicioPermisos {
/// Solicita todos los permisos necesarios para el modo multidispositivo.
/// Retorna true si todos los permisos fueron concedidos.
static Future<bool> solicitarPermisosNearby(BuildContext context) async {
final permisos = <Permission>[
Permission.locationWhenInUse,
];
// Android 12+ necesita permisos BT específicos
if (Platform.isAndroid) {
permisos.addAll([
Permission.bluetoothAdvertise,
Permission.bluetoothConnect,
Permission.bluetoothScan,
Permission.nearbyWifiDevices,
]);
}
// Solicitar todos
final resultados = await permisos.request();
if (!context.mounted) return false;
final l10n = AppLocalizations.of(context)!;
// Verificar cuáles fueron denegados
final denegados = <String>[];
for (final entry in resultados.entries) {
if (!entry.value.isGranted) {
denegados.add(_nombrePermiso(entry.key, l10n));
}
}
if (denegados.isEmpty) return true;
// Mostrar diálogo con los permisos que faltan
if (context.mounted) {
final abrirConfig = await showDialog<bool>(
context: context,
builder: (ctx) => AlertDialog(
title: Text(l10n.permissionsNeededTitle),
content: Text(
'${l10n.permissionsNeededBody}\n\n'
'${denegados.map((d) => '• $d').join('\n')}\n\n'
'${l10n.openAppSettingsQuestion}',
),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx, false),
child: Text(l10n.cancel),
),
TextButton(
onPressed: () => Navigator.pop(ctx, true),
child: Text(l10n.openSettings),
),
],
),
);
if (abrirConfig == true) {
await openAppSettings();
}
}
return false;
}
static String _nombrePermiso(Permission p, AppLocalizations l10n) {
if (p == Permission.locationWhenInUse) return l10n.permissionLocation;
if (p == Permission.bluetoothAdvertise) {
return l10n.permissionBluetoothAdvertise;
}
if (p == Permission.bluetoothConnect) {
return l10n.permissionBluetoothConnect;
}
if (p == Permission.bluetoothScan) return l10n.permissionBluetoothScan;
if (p == Permission.nearbyWifiDevices) return l10n.permissionNearbyWifi;
return p.toString();
}
}