import "dart:async"; import "package:flutter/foundation.dart"; import "package:quotegen_client/services/quote_api_v2.dart"; // tracks whether the render backend is reachable, so the ui can hide stuff // that actually needs it (video render, snapshot links etc) when its down class BackendStatusProvider extends ChangeNotifier { // start optimistic - dont want everything flashing away before the first check lands bool isOnline = true; bool hasChecked = false; Timer? _pollTimer; bool _disposed = false; BackendStatusProvider() { checkNow(); _pollTimer = Timer.periodic(const Duration(seconds: 15), (_) => checkNow()); } Future checkNow() async { final online = await QuoteGeneratorApiV2.checkHealth(); if (_disposed) return; hasChecked = true; if (online != isOnline) { isOnline = online; notifyListeners(); } } @override void dispose() { _disposed = true; _pollTimer?.cancel(); super.dispose(); } }