import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'classify_photo_platform_interface.dart'; /// An implementation of [ClassifyPhotoPlatform] that uses method channels. class MethodChannelClassifyPhoto extends ClassifyPhotoPlatform { /// The method channel used to interact with the native platform. @visibleForTesting final methodChannel = const MethodChannel('classify_photo'); @override Future getPlatformVersion() async { final version = await methodChannel.invokeMethod('getPlatformVersion'); return version; } @override Future>?> getPhoto() async { try { print('Flutter: 调用 getPhoto 方法'); final List? result = await methodChannel.invokeMethod>( 'getPhoto', ); print('Flutter: 收到原生返回结果: $result'); if (result == null) { print('Flutter: 结果为空'); return null; } return result.map((group) => Map.from(group)).toList(); } on PlatformException catch (e) { print('Flutter: Platform Exception: ${e.message}'); rethrow; } catch (e) { print('Flutter: Error: $e'); rethrow; } } // 实现获取存储信息的方法 @override Future> getStorageInfo() async { try { final result = await methodChannel.invokeMethod>('getStorageInfo'); if (result == null) { return {}; } // 转换返回的数据类型 return result.map((key, value) => MapEntry( key.toString(), (value as num).toInt(), )); } on PlatformException catch (e) { debugPrint('获取存储信息失败: ${e.message}'); return {}; } } }