USB 摄像头适配iPadOS17+

This commit is contained in:
2026-10-22 12:53:24 +08:00
parent 582242e9aa
commit 58a23ef218
18 changed files with 288 additions and 140 deletions

View File

@@ -39,6 +39,9 @@ public class UsbCameraAndroidPlugin implements FlutterPlugin, MethodChannel.Meth
@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
switch (call.method) {
case "isSupported":
result.success(true);
break;
case "getDeviceList":
result.success(engine.getDeviceList());
break;

View File

@@ -46,6 +46,19 @@ class UsbCameraAndroid {
return _eventStream!;
}
/// 当前平台/设备是否支持 USB(UVC)摄像头。
/// - Android:始终 true。
/// - iOS:仅 iPadOS 17+ 的 iPad 为 true;iPhone 或 iOS<17 为 false。
/// 通道未注册(异常)时保守返回 true,交由上层继续走原有枚举/错误流程。
static Future<bool> isSupported() async {
try {
final result = await _methodChannel.invokeMethod('isSupported');
return result as bool? ?? true;
} catch (_) {
return true;
}
}
/// 枚举当前连接的 UVC 设备。
static Future<List<UsbCameraDeviceInfo>> getDeviceList() async {
final List<dynamic> result =

View File

@@ -1,7 +1,8 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
/// Android 原生 UVC 预览画面。
/// 原生 UVC 预览画面(Android: AndroidView / iOS: UiKitView)。
class UsbCameraPreviewView extends StatelessWidget {
const UsbCameraPreviewView({super.key});
@@ -9,6 +10,13 @@ class UsbCameraPreviewView extends StatelessWidget {
@override
Widget build(BuildContext context) {
if (defaultTargetPlatform == TargetPlatform.iOS) {
return const UiKitView(
viewType: _viewType,
layoutDirection: TextDirection.ltr,
creationParamsCodec: StandardMessageCodec(),
);
}
return const AndroidView(
viewType: _viewType,
layoutDirection: TextDirection.ltr,

View File

@@ -13,6 +13,8 @@ flutter:
android:
package: com.maibu.usb_camera_android
pluginClass: UsbCameraAndroidPlugin
ios:
pluginClass: UsbCameraAndroidPlugin
dependencies:
flutter: