Overview
Wonderous integrates with the Unsplash API to fetch high-quality photos for each wonder. The integration uses theunsplash_client package and provides a service layer for managing photo collections and caching.
The Unsplash integration is currently used only for development tools. Production builds use pre-downloaded, self-hosted images for better performance and reliability.
Package Used
pubspec.yaml
unsplash_client package provides a Flutter-friendly interface to the Unsplash API, handling authentication, requests, and data parsing.
Architecture
The Unsplash integration consists of three main components:1. UnsplashService
The service layer handles all API communication with Unsplash.lib/logic/unsplash_service.dart
loadCollectionPhotos(String id): Fetches up to 25 photos from a collectionloadInfo(String id): Retrieves detailed information for a specific photo
2. UnsplashLogic
The logic layer manages photo collections and provides access to the service.lib/logic/unsplash_logic.dart
3. UnsplashPhotoData
The data model represents photo information and URL generation.lib/logic/data/unsplash_photo_data.dart
Photo Collections
Each wonder has a dedicated Unsplash collection. The collections are pre-mapped inUnsplashPhotoData.photosByCollectionId, which contains:
- Collection IDs as keys
- Lists of 24 photo IDs as values
Image Optimization
The integration supports multiple image sizes for optimal performance:Photo Sizes
- med: 400px (800px on high-DPI/desktop)
- large: 800px (1600px on high-DPI/desktop)
- xl: 1200px (2400px on high-DPI/desktop)
URL Generation
Images can be served from two sources:- Unsplash CDN:
getUnsplashUrl(int size)generates dynamic Unsplash URLs with quality and size parameters - Self-hosted:
getSelfHostedUrl()points to pre-downloaded images onwonderous.infofor production use
Development vs Production
The integration remains in the codebase to support:- Development tools
- Photo collection management
- Future content updates
API Authentication
The service uses Unsplash API credentials:Related Files
lib/logic/unsplash_logic.dart- Main logic layerlib/logic/unsplash_service.dart- API service implementationlib/logic/data/unsplash_photo_data.dart- Data models and collectionslib/_tools/unsplash_download_service.dart- Development tool for downloading photoslib/ui/common/unsplash_photo.dart- UI component for displaying photos