| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- 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<String?> getPlatformVersion() async {
- final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
- return version;
- }
- @override
- Future<List<Map<String, dynamic>>?> getPhoto() async {
- try {
- print('Flutter: 调用 getPhoto 方法');
- final List<dynamic>? result = await methodChannel.invokeMethod<List<dynamic>>(
- 'getPhoto',
- );
- print('Flutter: 收到原生返回结果: $result');
- if (result == null) {
- print('Flutter: 结果为空');
- return null;
- }
- return result.map((group) => Map<String, dynamic>.from(group)).toList();
- } on PlatformException catch (e) {
- print('Flutter: Platform Exception: ${e.message}');
- rethrow;
- } catch (e) {
- print('Flutter: Error: $e');
- rethrow;
- }
- }
- // 实现获取存储信息的方法
- @override
- Future<Map<String, int>> getStorageInfo() async {
- try {
- final result = await methodChannel.invokeMethod<Map<dynamic, dynamic>>('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 {};
- }
- }
- }
|