diff --git a/lib/photo_manager.dart b/lib/photo_manager.dart index 58c5ae70..87238e9e 100644 --- a/lib/photo_manager.dart +++ b/lib/photo_manager.dart @@ -25,6 +25,7 @@ export 'src/internal/progress_handler.dart'; export 'src/managers/caching_manager.dart'; export 'src/managers/notify_manager.dart'; export 'src/managers/photo_manager.dart'; +export 'src/managers/platform_delegate.dart'; export 'src/types/entity.dart'; export 'src/types/thumbnail.dart'; diff --git a/lib/src/managers/platform_delegate.dart b/lib/src/managers/platform_delegate.dart new file mode 100644 index 00000000..bb19af88 --- /dev/null +++ b/lib/src/managers/platform_delegate.dart @@ -0,0 +1,24 @@ +/// The delegate for platform +/// +/// Just inject some platform specific code. +abstract class PMPlatformDelegate { + static bool _isHarmony = false; + static bool get isHarmony => _isHarmony; +} + +/// The delegate have android, iOS and macOS implementation. +class CommonDelegate extends PMPlatformDelegate { + /// Registers this class as the default platform implementation. + static void registerWith() { + // ignore: avoid_print + print('registerWith CommonDelegate for photo_manager'); + } +} + +/// The delegate for harmony +class HarmonyDelegate extends PMPlatformDelegate { + /// Registers this class as the default platform implementation. + static void registerWith() { + PMPlatformDelegate._isHarmony = true; + } +} diff --git a/lib/src/utils/platform_utils.dart b/lib/src/utils/platform_utils.dart new file mode 100644 index 00000000..45433db5 --- /dev/null +++ b/lib/src/utils/platform_utils.dart @@ -0,0 +1,21 @@ +import 'dart:io'; + +import 'package:photo_manager/src/managers/platform_delegate.dart'; + +/// A utility class to check the platform. +class PlatformUtils { + /// The harmony must be injected by the platform delegate. + static bool get isOhos => PMPlatformDelegate.isHarmony; + + /// Wrapper for [Platform.isAndroid]. + static bool get isAndroid => Platform.isAndroid; + + /// Wrapper for [Platform.isIOS]. + static bool get isIOS => Platform.isIOS; + + /// Wrapper for [Platform.isMacOS]. + static bool get isMacOS => Platform.isMacOS; + + /// If the platform is iOS or macOS, return true. + static bool get isDarwin => Platform.isMacOS || Platform.isIOS; +} diff --git a/pubspec.yaml b/pubspec.yaml index 3e378e9e..d48287cd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -22,7 +22,14 @@ flutter: android: package: com.fluttercandies.photo_manager pluginClass: PhotoManagerPlugin + dartPluginClass: CommonDelegate ios: pluginClass: PhotoManagerPlugin + dartPluginClass: CommonDelegate macos: pluginClass: PhotoManagerPlugin + dartPluginClass: CommonDelegate + ohos: + package: com.fluttercandies.photo_manager + pluginClass: PhotoManagerPlugin + dartPluginClass: HarmonyDelegate