import 'package:shared_preferences/shared_preferences.dart'; /// 记录上一次使用的 USB 摄像头,插拔后优先重连。 class UsbCameraPrefs { static const String _lastDeviceIdKey = 'usb_camera_last_device_id'; static const String _lastResolutionKey = 'usb_camera_last_resolution'; static Future getLastDeviceId() async { final prefs = await SharedPreferences.getInstance(); return prefs.getString(_lastDeviceIdKey); } static Future setLastDeviceId(String? id) async { final prefs = await SharedPreferences.getInstance(); if (id == null) { await prefs.remove(_lastDeviceIdKey); return; } await prefs.setString(_lastDeviceIdKey, id); } static Future getLastResolution() async { final prefs = await SharedPreferences.getInstance(); return prefs.getString(_lastResolutionKey); } static Future setLastResolution(String? resolution) async { final prefs = await SharedPreferences.getInstance(); if (resolution == null) { await prefs.remove(_lastResolutionKey); return; } await prefs.setString(_lastResolutionKey, resolution); } }