classify_photo_method_channel.dart 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import 'package:flutter/foundation.dart';
  2. import 'package:flutter/services.dart';
  3. import 'classify_photo_platform_interface.dart';
  4. /// An implementation of [ClassifyPhotoPlatform] that uses method channels.
  5. class MethodChannelClassifyPhoto extends ClassifyPhotoPlatform {
  6. /// The method channel used to interact with the native platform.
  7. @visibleForTesting
  8. final methodChannel = const MethodChannel('classify_photo');
  9. @override
  10. Future<String?> getPlatformVersion() async {
  11. final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
  12. return version;
  13. }
  14. @override
  15. Future<List<Map<String, dynamic>>?> getPhoto() async {
  16. try {
  17. print('Flutter: 调用 getPhoto 方法');
  18. final List<dynamic>? result = await methodChannel.invokeMethod<List<dynamic>>(
  19. 'getPhoto',
  20. );
  21. print('Flutter: 收到原生返回结果: $result');
  22. if (result == null) {
  23. print('Flutter: 结果为空');
  24. return null;
  25. }
  26. return result.map((group) => Map<String, dynamic>.from(group)).toList();
  27. } on PlatformException catch (e) {
  28. print('Flutter: Platform Exception: ${e.message}');
  29. rethrow;
  30. } catch (e) {
  31. print('Flutter: Error: $e');
  32. rethrow;
  33. }
  34. }
  35. }