import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; /// Whether this device has any camera. Resolved once at startup (via the native /// channel, `PackageManager.FEATURE_CAMERA_ANY`) and cached so `build()` methods /// can read it synchronously — the QR scan button ([qrScanSupported]) and the /// photo-source sheet hide their camera options when it is false. /// /// Defaults to `true` so a normal phone never loses camera UI over a transient /// channel error; only genuinely camera-less devices (Chromebooks, Android /// Automotive, some TVs — kept installable by the `uses-feature required=false` /// in AndroidManifest) flip it to false. Non-Android platforms keep the default /// (iOS devices have a camera; desktop/web gate camera UI elsewhere). bool _deviceHasCamera = true; bool get deviceHasCamera => _deviceHasCamera; @visibleForTesting set deviceHasCamera(bool value) => _deviceHasCamera = value; const _channel = MethodChannel('org.comunes.tane/coarse_location'); /// Queries the native camera-presence check and caches it. Called once during /// bootstrap, before the first real frame, so synchronous readers see the right /// value. Android-only; elsewhere the default stands. Never throws — a channel /// error leaves the safe default in place. Future initCameraAvailability() async { if (defaultTargetPlatform != TargetPlatform.android) return; try { final has = await _channel.invokeMethod('hasCamera'); if (has != null) _deviceHasCamera = has; } catch (_) { // Keep the default; a normal phone shouldn't lose camera UI over this. } }