copyAssetsToDocuments method

Future<void> copyAssetsToDocuments()

Implementation

Future<void> copyAssetsToDocuments() async {
  final directory = await getApplicationDocumentsDirectory();
  final bundle = rootBundle;
  final assets = await bundle.loadString('AssetManifest.json');
  var assetList = jsonDecode(assets) as Map<String, dynamic>;
  assetList.removeWhere((key, value) =>
      !key.contains('lforms/webcomponent') ||
      key.contains('lforms/webcomponent/.'));

  for (final assetPath in assetList.keys) {
    final assetData = await bundle.load(assetPath);
    String correctedAssetPath = assetPath.split('assets/').last;
    final file = File('${directory.path}/$correctedAssetPath');
    await file.create(recursive: true);
    await file.writeAsBytes(assetData.buffer.asUint8List());
  }
}