{"id":31041749,"url":"https://github.com/imsamgarg/firebase_cached_image","last_synced_at":"2025-09-14T10:40:51.518Z","repository":{"id":62458735,"uuid":"493826839","full_name":"imsamgarg/firebase_cached_image","owner":"imsamgarg","description":"Cache Manager and Cached ImageProvider for Firebase Cloud Storage Objects.","archived":false,"fork":false,"pushed_at":"2025-08-24T19:50:57.000Z","size":300,"stargazers_count":12,"open_issues_count":11,"forks_count":18,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-24T22:52:29.391Z","etag":null,"topics":["dart","firebase","firebase-storage","flutter"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imsamgarg.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-05-18T21:13:39.000Z","updated_at":"2025-08-24T19:50:50.000Z","dependencies_parsed_at":"2024-02-06T17:28:42.727Z","dependency_job_id":"106a7506-703b-43bd-ae0f-52b156b864b8","html_url":"https://github.com/imsamgarg/firebase_cached_image","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/imsamgarg/firebase_cached_image","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imsamgarg%2Ffirebase_cached_image","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imsamgarg%2Ffirebase_cached_image/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imsamgarg%2Ffirebase_cached_image/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imsamgarg%2Ffirebase_cached_image/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imsamgarg","download_url":"https://codeload.github.com/imsamgarg/firebase_cached_image/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imsamgarg%2Ffirebase_cached_image/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275094398,"owners_count":25404446,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-14T02:00:10.474Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart","firebase","firebase-storage","flutter"],"created_at":"2025-09-14T10:40:40.790Z","updated_at":"2025-09-14T10:40:51.495Z","avatar_url":"https://github.com/imsamgarg.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Firebase_Cached_Image\n\nCache Manager and Cached ImageProvider for Firebase Cloud Storage Objects.\n\n## Set up\n\nSetup firebase (https://firebase.google.com/docs/flutter/setup).\n\n## Web Support\n\nWeb support is experimental. To enable it, add the following line in your main() function:\n\n```dart\nFirebaseCacheManagerConfig.webSupport = true;\n```\n\nOn the web, It uses `indexed_db` for caching the files. All the files are directly saved to the browser's IndexedDB store. Read more about IndexedDB here (https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API).\n\n# Usage\n\n## Firebase Image Provider\n\nTo display an image from Firebase Cloud Storage, use FirebaseImageProvider as the ImageProvider for the Flutter Image widget.\n\n```dart\nImage(\n  image: FirebaseImageProvider(\n    FirebaseUrl(\"gs://bucket_f233/logo.jpg\")\n  ),\n),\n```\n\nYou can declare `FirebaseUrl` in following ways:\n\n```dart\nFirebaseUrl(\"gs://bucket_f233/logo.jpg\")\nFirebaseUrl(\"https://firebasestorage.googleapis.com/b/bucket/o/logo.jpg\")\nFirebaseUrl.fromReference(FirebaseStorage.instance.ref(\"images/image.jpg\"));\n```\n\n## Cache Options\n\nCustomize caching behavior with `CacheOptions`:\n\n```dart\nImage(\n  image: FirebaseImageProvider(\n    FirebaseUrl(\"gs://bucket_f233/logo.jpg\"),\n    options: CacheOptions(\n      checkIfFileUpdatedOnServer: false,\n      source: Source.cacheServer,\n    ),\n  ),\n),\n```\n\n- **Default behavior**: Load from cache if available; otherwise fetch from server and then cache.  \n- **Always fetch latest from server**:  \n  ```dart\n  source: Source.server,\n  ```\n- **Fetch from server only if updated since last fetch**:  \n  ```dart\n  checkIfFileUpdatedOnServer: true,\n  ```\n\n\u003e **Note:** Image update checks require fetching metadata (last modified timestamp) from Firebase Storage.  \nThis is a **Class B operation** in Google Cloud Storage, which may incur charges after 50,000 free operations per month. [Pricing details](https://cloud.google.com/storage/pricing#price-tables).\n---\n\n\n## Firebase Cache Manager\n\nFor more control and support beyond images (e.g., docs, videos), use `FirebaseCacheManager`.\n\n### Download and Cache a File\n\n_Not supported on web._\n\n```dart\nfinal file = await FirebaseCacheManager().getSingleFile(\n  FirebaseUrl(\"gs://bucket_f233/doc.docx\"),\n);\nprint(file); // Local cached file path (useful for sharing/reading)\n```\n\nYou can also use `getSingleObject` method to get the file as bytes:\n\n_Supported on web._\n\n```dart\nfinal cachedObject = await FirebaseCacheManager().getSingleObject(\n  FirebaseUrl(\"gs://bucket_f233/doc.docx\"),\n);\n\nprint(cachedObject.rawBytes); // Uint8List of file bytes\n```\n\n### Pre-cache a File\n\nPre-download files you know will be needed soon (e.g., profile pictures at app start):\n\n```dart\nawait FirebaseCacheManager().preCache(\n  FirebaseUrl(\"gs://bucket_f233/profile_pic.jpg\"),\n);\n```\n\n### Refresh a Cached File\n\nUpdate a cached file if it has changed on the server:\n\n```dart\nawait FirebaseCacheManager().refreshCachedFile(\n  FirebaseUrl(\"gs://bucket_f233/profile_pic.jpg\"),\n);\n```\n\n### Copy a Local File to Cache\n\nAvoid re-downloading by copying an existing local file into the cache.  \n_Not supported on web._\n\n```dart\nfinal filePath = \"/storage/file.jpg\";\nfinal cachedFilePath = await FirebaseCacheManager().copyToCache(\n  FirebaseUrl(\"gs://bucket_f233/profile_pic.jpg\"),\n  filePath,\n);\n```\n\n### Delete a Cached File\n\n```dart\nawait FirebaseCacheManager().delete(\n  FirebaseUrl(\"gs://bucket_f233/logo.jpg\"),\n);\n```\n\n### Clear Cache\n\n```dart\n// Clear entire cache (Supported on web)\nawait FirebaseCacheManager().clearCache();\n\n// Clear files older than 20 days (Not supported on web)\nawait FirebaseCacheManager().clearCache(modifiedBefore: Duration(days: 20));\n```\n\n### Custom Sub-Directory\n\nSave cached files in a custom subdirectory inside the system’s temporary directory.  \n_Default:_ `\"flutter_cached_image\"`\n\n```dart\nfinal manager = FirebaseCacheManager(subDir: \"profile_pictures\");\n```\n\nThis allows organizing cached files by category:\n\n```dart\nfinal profilePicturesCacheManager = FirebaseCacheManager(subDir: \"profile_pictures\");\nfinal postsCacheManager = FirebaseCacheManager(subDir: \"posts\");\n\n// Clear only \"posts\" cache\nawait postsCacheManager.clearCache();\n```\n\n### Platform Support\n\n| Method                       | Mobile       | Web              |\n| ---------------------------- | ------------ | ---------------- |\n| `getSingleFile()`            | ✅ Supported | ✅ Supported     |\n| `preCache()`                 | ✅ Supported | ✅ Supported     |\n| `refreshCachedFile()`        | ✅ Supported | ✅ Supported     |\n| `copyToCache()`              | ✅ Supported | ❌ Not Supported |\n| `delete()`                   | ✅ Supported | ✅ Supported     |\n| `clearCache()` (all files)   | ✅ Supported | ✅ Supported     |\n| `clearCache(modifiedBefore)` | ✅ Supported | ❌ Not Supported |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimsamgarg%2Ffirebase_cached_image","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimsamgarg%2Ffirebase_cached_image","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimsamgarg%2Ffirebase_cached_image/lists"}