Hi I am trying to access a asset in my dart function but I don't know how to set the path properly.
Would it be possible to share the code to see how your imports and folder structure are doing?
I have some functions in dart, what I needed to do was import them from the dart project name:
pubspec.yaml:
name: my_function
in the archives:
import 'package:my_function/modules/model/any_files.dart’;
For example rootBundle.load("lib/example.txt'')
import 'dart:async' show Future; import 'package:flutter/services.dart' show rootBundle;
Future<String> loadAsset() async { return await rootBundle.loadString('assets/my_text.txt'); }
Or if you have the BuildContext (inside a widget) you can use DefaultAssetBundle. This is recommended because it allows switching asset bundles at runtime, which is useful for multilingual assets.
Future<String> loadAsset(BuildContext context) async { return await DefaultAssetBundle.of(context).loadString('assets/my_text.txt'); }
Recommended threads
- router_deployment_not_found
I updated my function a few times and now i am getting the error: router_deployment_not_found I even reverted back to my original code but i am still getting th...
- Usage of the new Client() and dealing wi...
Hey guys, just a quick one - we had some web traffic the other day and it ended up bombing out - To put in perspective of how the app works, we have a Nuxt Ap...
- [Beginner] CLI --queries Syntax Error & ...
Hi everyone! I am a beginner with Appwrite and trying to use the CLI, but I'm stuck with a syntax error. Any guidance would be greatly appreciated! 🙏 **Enviro...