loadAssets static method

Future<List<String>> loadAssets(
  1. List<String> assetPaths, {
  2. AssetBundle? assetBundle,
})

Loads a list of asset paths and returns the bundles assets as raw strings.

  • assetPaths: List of paths to the bundled assets to load.
  • {assetBundle}: Optional context to use. Defaults to rootBundle.
FutureBuilder<List<String>>(
  future: HighchartsHelpers.loadAssets(['assets/highcharts.js']),
  builder: (context, snapshot) {
    if (!snapshot.hasData) return const CircularProgressIndicator();
    return HighchartsChart(
      HighchartsOptions(),
      javaScriptModules: snapshot.data!
    );
  }
)

Implementation

static Future<List<String>> loadAssets(List<String> assetPaths,
    {AssetBundle? assetBundle}) {
  final bundle = assetBundle ?? rootBundle;
  return Future.wait(assetPaths.map((path) => bundle.loadString(path)));
}