fix(push): do not call UnifiedPush outside Android

UnifiedPush only exists on Android. On iOS getDistributor() and
getDistributors() throw UnimplementedError, which surfaced as an uncaught
error from the Push tile in Settings. Report an empty state instead.
This commit is contained in:
Julius Joska
2026-10-11 16:12:41 +02:00
parent 09ef54ef69
commit 6f9b08e844
+8 -3
View File
@@ -138,10 +138,14 @@ class PushService {
} }
/// Seznam nainstalovaných distributorů (pro výběr v nastavení). /// Seznam nainstalovaných distributorů (pro výběr v nastavení).
Future<List<String>> distributors() => UnifiedPush.getDistributors(); /// UnifiedPush existuje jen na Androidu; jinde by volání pluginu vyhodilo
/// UnimplementedError (iOS: dlaždice Push v Nastavení).
Future<List<String>> distributors() async =>
Platform.isAndroid ? UnifiedPush.getDistributors() : const [];
/// Aktuálně uložený distributor (null = push vypnutý / nevybraný). /// Aktuálně uložený distributor (null = push vypnutý / nevybraný).
Future<String?> currentDistributor() => UnifiedPush.getDistributor(); Future<String?> currentDistributor() async =>
Platform.isAndroid ? UnifiedPush.getDistributor() : null;
/// Vybere konkrétního distributora a zaregistruje se u něj. /// Vybere konkrétního distributora a zaregistruje se u něj.
Future<void> useDistributor(String distributor) async { Future<void> useDistributor(String distributor) async {
@@ -158,7 +162,7 @@ class PushService {
} }
Future<bool> get isEnabled async => Future<bool> get isEnabled async =>
(await UnifiedPush.getDistributor()) != null; Platform.isAndroid && (await UnifiedPush.getDistributor()) != null;
// ── Režimy (off / up / fcm) ───────────────────────────────────────── // ── Režimy (off / up / fcm) ─────────────────────────────────────────
@@ -167,6 +171,7 @@ class PushService {
Future<String> currentMode() async { Future<String> currentMode() async {
final mode = await PushBootstrap.readMode(); final mode = await PushBootstrap.readMode();
if (mode != 'off') return mode; if (mode != 'off') return mode;
if (!Platform.isAndroid) return mode;
return (await UnifiedPush.getDistributor()) != null ? 'up' : 'off'; return (await UnifiedPush.getDistributor()) != null ? 'up' : 'off';
} }