36 lines
1.1 KiB
Dart
36 lines
1.1 KiB
Dart
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<String?> getLastDeviceId() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
return prefs.getString(_lastDeviceIdKey);
|
|
}
|
|
|
|
static Future<void> setLastDeviceId(String? id) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
if (id == null) {
|
|
await prefs.remove(_lastDeviceIdKey);
|
|
return;
|
|
}
|
|
await prefs.setString(_lastDeviceIdKey, id);
|
|
}
|
|
|
|
static Future<String?> getLastResolution() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
return prefs.getString(_lastResolutionKey);
|
|
}
|
|
|
|
static Future<void> setLastResolution(String? resolution) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
if (resolution == null) {
|
|
await prefs.remove(_lastResolutionKey);
|
|
return;
|
|
}
|
|
await prefs.setString(_lastResolutionKey, resolution);
|
|
}
|
|
}
|