implemented a backend-independent emergency notice system

This commit is contained in:
2026-07-15 20:30:20 +02:00
parent e8c6ac1c65
commit 7c1f5c06df
11 changed files with 599 additions and 3 deletions
@@ -0,0 +1,34 @@
import 'package:dio/dio.dart';
import 'emergency_notice.dart';
/// Loads the emergency notice from a foreign URL over a standalone [Dio]
/// instance — no MarianumConnect interceptors, base URL or auth. That keeps the
/// fallback fully independent of the backend it is meant to survive.
///
/// Fail-safe by contract: if the server is unreachable, times out, answers with
/// a non-2xx status or delivers unparsable content, [fetch] returns `null` and
/// nothing is shown. It never throws.
class EmergencyNoticeClient {
const EmergencyNoticeClient();
Future<EmergencyNotice?> fetch(String url) async {
try {
final dio = Dio(
BaseOptions(
connectTimeout: const Duration(seconds: 5),
receiveTimeout: const Duration(seconds: 5),
sendTimeout: const Duration(seconds: 5),
responseType: ResponseType.plain,
),
);
final response = await dio.get<String>(url);
final raw = response.data;
if (raw == null || raw.isEmpty) return null;
return EmergencyNotice.parse(raw);
} catch (_) {
// Server down / timeout / bad status / malformed body: show nothing.
return null;
}
}
}