External Asset Bundle

The External Asset Bundle package works exactly like a rootBundle or DefaultAssetBundle, but loads resources from an external location like the application or library path. It also implements caching for resource loading.

It's very useful if you want to use resources from a folder that is temporary or located on external storage.

You can use Image.asset to create an Image instance as the default bundle does:

var externalAssetBundle = ExternalAssetBundle("download/folder/assets");
var image = Image.asset(
      bundle: externalAssetBundle,	//Don't forget to use your own AssetBundle!

Or load a string file from the path very easily:

var stringContent = externalAssetBundle.loadString("some-text-file.txt");

The ExternalAssetBundle implements the abstract class of AssetBundle, so it should work every place that needs an AssetBundle.

Additionaly, you won't need to predefine your folder structure in the pubspec.yaml file. The folder structure is obtained dynamically. But you still need to follow the rules for constructing the default assets folder.

Read more: Assets and Images


Add external_asset_bundle as dependency to your pubspec file.

external_asset_bundle: 1.0.0



The only thing you need to do is to create an ExternalAssetBundle instance:

import 'package:external_asset_bundle/external_asset_bundle.dart';

var externalAssetBundle = ExternalAssetBundle("path/to/any/folder");

Use it!

You can use it as any AssetBundle:

var image = Image.asset(
      bundle: externalAssetBundle,
var stringContent = externalAssetBundle.loadString("some-text-file.txt");

If you manage your folder structure like this:


The variant could be correctly found by Image.asset.


The resources could be cached by initializing the ExternalAssetBundle with the enableBinaryCache parameter on:

var externalAssetBundle = ExternalAssetBundle("path", enableBinaryCache:true);

But loadString will use its own cache parameter to determine whether to use the caching.


Please report issues on my Github page!