Dimas N AL
Dimas N AL

Reputation: 145

How to get path from cached images network in flutter?

i'm new in flutter i want to know how to get path from cached images network in flutter or how to save network image to asset image and get the path of that image?

Upvotes: 5

Views: 10875

Answers (3)

Vishal_VE
Vishal_VE

Reputation: 2137

All Cache is stored in one particular place for that app. Any will get trigger their cache for further use. Use flutter_cache_manager to find out data.

Future<String> _cachePath(String cacheUrl) async {
  final cache = await CacheManager.getInstance();
  var file = await cache.getFile(imageUrl);
  return file.path;
}

Upvotes: 0

sjsam
sjsam

Reputation: 21965

The newer way to do this is using DefaultCacheManager from the Flutter Cache Manager package.

final cache = DefaultCacheManager(); // Gives a Singleton instance
final file = await cache.getSingleFile(yourURL);
// Now use file.path

Upvotes: 12

Edman
Edman

Reputation: 5605

cached_network_image uses the flutter_cache_manager under the hood to save images locally (code here).

To find the path you need to access the file through the cache manager.

import 'package:flutter_cache_manager/flutter_cache_manager.dart';

Future<String> _findPath(String imageUrl) async {
  final cache = await CacheManager.getInstance();
  final file = await cache.getFile(imageUrl);
  return file.path;
}

Upvotes: 10

Related Questions