flutter_cache_manager icon indicating copy to clipboard operation
flutter_cache_manager copied to clipboard

IOFileSystem - problem using the Customize example in the docs for 2.0.0

Open sowens-csd opened this issue 3 years ago • 7 comments

I'm upgrading from the previous version to 2.0.0 and trying to follow the new Customize instructions to use CacheManager instead of BaseCacheManager. The reference to IOFileSystem doesn't resolve. What am I doing wrong?

CacheManager(
        Config(
          key,
          stalePeriod: const Duration(days: 7),
          maxNrOfCacheObjects: 60,
          repo: JsonCacheInfoRepository(databaseName: key),
          fileSystem: IOFileSystem(key),
          fileService: HttpFileService(),
        ),
      );

sowens-csd avatar Oct 16 '20 21:10 sowens-csd

@sowens-csd I had the same issue and had to check out the example for a little help. This worked for me.

import 'package:file/file.dart';
import 'package:file/local.dart';
import 'package:flutter_cache_manager/src/storage/file_system/file_system.dart' as c;
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';

class IOFileSystem implements c.FileSystem {
  final Future<Directory> _fileDir;

  IOFileSystem(String key) : _fileDir = createDirectory(key);

  static Future<Directory> createDirectory(String key) async {
    var baseDir = await getTemporaryDirectory();
    var path = p.join(baseDir.path, key);

    var fs = const LocalFileSystem();
    var directory = fs.directory((path));
    await directory.create(recursive: true);
    return directory;
  }

  @override
  Future<File> createFile(String name) async {
    assert(name != null);
    return (await _fileDir).childFile(name);
  }
}

befora avatar Oct 18 '20 23:10 befora

I see that IOFileSystem is not exported by the package, so that could be it. However, IOFileSystem(key), is the default so that is not customising anything. The example of @sethchhim gives you more options to customise, for example the base path of where the images are stored.

renefloor avatar Oct 19 '20 06:10 renefloor

Excellent, if that's the default then I don't need it. You can probably remove that from the sample in your README but I see you have a doc label so you were likely planning to do that.

Just in case I need to customize it in the future, should it be exported by the package?

sowens-csd avatar Oct 19 '20 21:10 sowens-csd

I think so, but I'll have to try it.

renefloor avatar Oct 20 '20 06:10 renefloor

@renefloor do you plan to export IOFileSystem? @sethchhim 's workaround is okay but temporary for me (it is a duplicated code with warning "Don't import implementation files from another package")...

jozef-pridavok avatar Dec 07 '20 21:12 jozef-pridavok

@renefloor Until file_system.dart is included in exported files, custom implementations are only possible by importing internal dependencies, which is bad practice. Any plans for exporting FileSystem?

kengu avatar May 10 '21 07:05 kengu

+1 for this, we can't properly customize the fileSystem class as of now. Also, it would be great if we could somehow affect the directory of the "cached" files (i.e ApplicationsDirectory instead of CacheDirectory, so we don't need to subclass and overwrite existing logic.

idish avatar Sep 29 '21 08:09 idish