How luongcuong244/image_downloader works
This project is a Flutter plugin designed to handle image (and movie) downloads on both Android and iOS. Its primary purpose is to provide a unified API from Dart that leverages platform-native functionality to download files from the Internet and save them—retaining essential metadata like Exif and GPS information—to either the mobile device’s photo library (iOS) or a specified directory (Android). In addition, the project includes an example app showing how to utilize the plugin on both platforms.
Main Components
• Flutter/Dart Layer: Represented by the Dart API in the “lib” folder and the example project under “example/lib”. This layer is where client code interacts with the plugin’s functions such as downloadImage(), findPath(), open(), etc.
• Plugin Bridge (Platform Channel): This abstraction connects the Dart code to the native implementations. Although it isn’t a separate folder by name, it is an implied layer using Flutter’s platform channel mechanism.
• Android Native Implementation: Found in the “android” folder (especially under “android/src/main/kotlin/com/ko2ic/imagedownloader”), this contains native Kotlin classes like ImageDownloaderPlugin.kt and FileProvider.kt, as well as Android-specific configurations (e.g., AndroidManifest.xml, Gradle files, and XML resource for provider_paths.xml in the example project). This layer interacts with Android OS services—file systems, external storage directories, and permissions.
• iOS Native Implementation: Contained in the “ios” folder (and additionally in “example/ios”), with Objective-C/Swift code in “ios/Classes” (e.g., ImageDownloaderPlugin.h/.m, SwiftImageDownloaderPlugin.swift). This part handles interactions with iOS-specific APIs such as the Photo Library and preview functionality (using UIDocumentInteractionController).
• Underlying OS Services: These are the native platform services which include:
• On Android: File storage, permission management, and Intent-based file preview.
• On iOS: Photo Library access, metadata handling, and file preview implementations.
Relationships and Interactions
• The Platform Channel then dispatches these requests to their respective native implementations.
• On Android, the native layer communicates directly with Android’s system services (e.g., downloads, file storage, file provider for sharing files).
• On iOS, the native layer interfaces with system-level components like the Photo Library and UIDocumentInteractionController for previewing files.
• The example application illustrates usage of the plugin, so you might want to add a separate “Example App” component that consumes the plugin’s API.
Architectural Patterns and Design Principles
• Separation of Concerns: Notice how the Flutter plugin cleanly separates cross-platform (Dart) logic from platform-specific implementations.
• Plugin Architecture: Utilizes Flutter’s platform channels to bridge between Dart and native code.
• Modularity and Extensibility: With separate directories for each platform (android and ios), it’s easy to update or extend the native logic independently.
• Configuration and Platform-Specific Customizations: The configuration files (e.g., AndroidManifest.xml, Gradle build files, iOS Info.plist) highlight how the plugin is configured for each platform regarding permissions and provider details.
Relevant Technologies and Frameworks
• Flutter and Dart: Core for the cross-platform API.
• Kotlin for Android: Used for the native part of the plugin.
• Swift/Objective-C for iOS: Used in the iOS native implementation.
• Android FileProvider: Critical for enabling file sharing and preview on Android.
• iOS UIDocumentInteractionController: For preview functionality within iOS.
• Gradle and Xcode: For build and project management of native components.